Voice RSS – Let your blog speak – Part I January 19, 2009
How often have you thought that it would be a cool idea to hear your favorite RSS feeds? If you are a blogger or a webmaster, wouldn’t it be a nice addition to have your blogs be spoken to the reader?
Well, think no more. Code below shows a simple implementation of an Voice RSS Reader.
Here are the key steps of this application:
- Specify the URL for the RSS feeds you are interested in.
- Ask the user to select a feed by pressing the appropriate keys on the keypad
- Fetch the RSS feeds using a helper function
- Speak the title of the feeds and if user is interested, the description of that feed
This example demonstrates advanced usage of the prompt API. In particular, check out:
- Usage of timeout to control the duration within which a user input is requested.
- Usage of barge_in to specify if the user can interrupt the prompt being played.
- Finally, a simple way to specify dtmf grammar of expecting a single digit dtmf input
Enjoy the simplicity of VoicePHP. In Part II, we will enhance this application using ASR (automatic speech recognition).
<?php
include_once ("rssutils.php");
// Feed Provider Name & URL (Below list in alphabetical order)
$rss = array (
array('Giga Om', 'http://feedproxy.google.com/ommalik'),
array('New York Times', 'http://www.nytimes.com/services/xml/rss/nyt/Americas.xml'),
array('Plugged In', 'http://feedproxy.google.com/pluggd'),
array('Read Write Web', 'http://feeds2.feedburner.com/readwriteweb'),
array('Tech Crunch', 'http://feedproxy.google.com/TechCrunch'),
array('USA Today', 'http://rssfeeds.usatoday.com/usatoday-NewsTopStories')
);
$feedcount = count($rss);
$prompttext = '';
for($i = 1; $i <= $feedcount; $i++)
$prompttext .= "press $i to hear news from {$rss[$i-1][0]}, ";
$prompttext .= 'press 0 to exit';
echo "Welcome to the Voice PHP demo of voice RSS reader.";
$choice = '';
$loop_count = 3;
while($loop_count) {
setvoiceoption("voicetype", 'female');
$choice = prompt($prompttext, 1, 3, "dtmf:1");
if($choice == '0')
break;
if($choice > $feedcount) {
echo "Invalid choice, try again";
$loop_count--;
continue;
}
speak_rss($rss[$choice-1][0], $rss[$choice-1][1]);
break;
}
echo "Thank you for trying out Voice PHP demo.";
function speak_rss ($name, $url) {
// Get RSS feeds from the selected feed using a helper function
if (false == get_rss($url, 5, 512, &$result)) {
return;
}
$loop_count = 3;
while($loop_count) {
setvoiceoption("voicetype", 'female');
echo("Reading news title from $name now. At any time,
press 1 to get details on the news,
press 0 to exit.");
for($count=0; $count < count($result); $count++) {
$choice = '';
$voicetype = ($count&1)?"female":"male";
setvoiceoption("voicetype", $voicetype);
$choice = prompt($result[$count]['title'], 1, 1, "dtmf:1");
if($choice == '1')
$choice = prompt($result[$count]['description'], 1, 1, "dtmf:1");
if($choice == '0')
return;
}
sleep(1);
$loop_count--;
}
} // End of function speak_rss
?>
Try It Now!
Click the button below or call +15672449192 to run the application.
Does'nt it look easy? Try VoicePHP for yourself and feel free to modify the above script. VoicePHP is easy and accessible from your free TringMe account. More details at http://voicephp.com/howitworks.html
Leave a Comment
If you would like to make a comment, please fill out the form below.






[...] TringMe launches a new VoicePHP blog with a code example a day. Yusuf and his team are doing a great job developing examples so even someone like me with a basic code understanding can work out how it's working and the power of applications we could put VoicePHP to. (tags: voip voicephp tringme) [...]
[...] is an example running at the site for you to check out! Tags: Voice RSS Reader, Tringme, voicePHP Snap Voip Copyright © 2005-2008 [...]