Getting Past the VoiceXML Limitations – VoicePHP Audio Player February 3, 2009

One of the shortcomings of VoiceXML is its inability to do pause, resume, forward and rewind during a voice playback functionality. VoiceXML specification doesn’t even include such increasingly common features. Brian Brown has succintly identified the lack of same in a well-written article “Is VoiceXML the Right Tool for Your Voice Application”?

Lack of such functionalities really impact the usability of the applications. For example, lets say you are accessing your voicemails. The voicemail is being played is a long one and you probably didn’t hear the previous sentense very well and want to rewind a bit, you are stuck now.  There is no way this can built in VoiceXML due to lack of state information about voice stream being played. Surprising? yeah, but true!

Contrast that with the ability of VoicePHP and see for yourself how easy it is to build a audio playback application. Potential applications that can benefit from this functionality are an email reader, voicemail player, a music on demand media player etc.

This application demonstrates:

<?php
echo "Welcome to Voice PHP audio player";
echo 
"Audio playback will begin shortly. At anytime, press 2 to pause,
      3 to stop,
      4 to rewind,
      5 to fast forward,
      6 to restart and
      0 to exit."

$play 1;
$offset=5000;    // Rewind and Fast-Forward Offset
$streampos 0;

while(
$play) { 
    
$choice play("http://code.voicephp.com/samples/3732.pcm",true,$streampos,1);
    
$streampos $_VOICEPHP['streampos'];
    
$streamlen $_VOICEPHP['streamlen'];
    
    switch(
$choice) { 
        case 
0// Exit
            
exit();
        case 
4// Rewind
            
$streampos = ($streampos<$offset)?0:($streampos-$offset);
            break;
        case 
5// Forward
            
$streampos = ($streampos>($streamlen-$offset))?0:($streampos+$offset);
            break; 
        case 
2// Pause
            
if(prompt("Playback paused. Press 1 to resume, any key to exit",1,10,"dtmf:1")!="1") { 
                
$play=0;
                continue;
            }
            break;
        case 
""// Playback Completed.
        
case 3:  // Stop
            
if(prompt("Playback paused. Press 1 to resume, any key to exit",1,10,"dtmf:1")!="1") { 
                
$play=0;
                continue;
            }
        case 
6// Restart
            
$streampos 0;
            break;
    }
}    
?>

Download source code

In part two of this application, we will demonstrate a fully functional media player application. We will show also share with you a re-usable mediaplayer function which implements the common features of a mediaplayer.

Try It Now!

Click the button below or call +15672445604 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.

Name (required)

Email (required)

Website

Comments

3 Comments so far
  1. [...] More: Getting Past the VoiceXML Limitations – VoicePHP Audio Player … [...]

  2. [...] think it’s great that other platforms are providing innovative ways to provide language-specific methods for achieving audio control in [...]

  3. [...] In an article “Is VoiceXML the Right Tool for Your Voice Application?”, Brian Brown identifies very precise weaknesses of VoiceXML.  For example,  when even a basic voice controls (pause, resume etc) are not available in VoiceXML, how it can be even considered the language to program voice?  He nailed the problem very well. Look at how VoicePHP addresses it beautifully in a sample application here .  [...]

© Copyright TringMe., All rights reserved. - Blog powered by Wordpress - Designed by Speckyboy