Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make voiceXML to read the result returned by the server

I am new in voiceXML and I am wondering how to read a value return by the server after post. I want voiceXML to read the server's response. According to voiceXML documentation, I understand that the result should be in XML.

Here is my node.js/express.js code that receives the result:

app.post("/getData", function (req, res) {
    console.log(JSON.stringify(req.body));
    res.header('Content-Type','text/xml').send('<?xml version="1.0" ?> <vxml version="2.0"> <block> <prompt> The time in Milwaukee is 10 </prompt> </block> </vxml>');
});

Here is the screenshot showing that I am successfully receiving the posted content:

enter image description here

Here is the screenshot showing that I am successfully sending the XML result: enter image description here

Here is my voiceXML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN" "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml xmlns="http://www.w3.org/2001/vxml" xmlns:bevocal="http://www.bevocal.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
    <form scope="dialog">
        <field name="name" modal="false">
            <grammar src="grammars.grammar#Names"/>
            <prompt>Whats your name?</prompt>
            <filled>
                <prompt>Hello <value expr="name"/>
                </prompt>
            </filled>
        </field>

        <field name="city" modal="false">
            <grammar src="grammars.grammar#Cities"/>
            <prompt>What city are you from?</prompt>
            <filled>
                <prompt>You are from <value expr="city"/>
                </prompt>
            </filled>
        </field>

        <field name="country" modal="false">
            <grammar src="grammars.grammar#Countries"/>
            <prompt>What country are you from?</prompt>
            <filled>
                <prompt>You are from <value expr="country"/>
                </prompt>
            </filled>
        </field>

        <field name="cityTime">
            <prompt>
                What city would you like the time for?
            </prompt>
            <grammar type="application/x-nuance-gsl">
                [denver (san francisco) ]
            </grammar>
        </field>
        <field name="formatTime">
            <prompt>
                Twelve hour or twenty four hour clock?
            </prompt>
            <grammar type="application/x-nuance-gsl">
                [[twelve (twenty four)] ?hour]
            </grammar>
        </field>
        <block>
            <submit next="http://65.29.170.122/getData" method="post" namelist="name city country cityTime formatTime" />
        </block>
    </form>
</vxml>
like image 919
Node.JS Avatar asked Nov 28 '15 18:11

Node.JS


People also ask

What is VoiceXML with example?

VoiceXML has tags that instruct the voice browser to provide speech synthesis, automatic speech recognition, dialog management, and audio playback. The following is an example of a VoiceXML document: <vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"> <form> <block> <prompt> Hello world! </

What is Subdialog in Vxml?

Description. Invokes another dialog as a subdialog of the current one. The subdialog is a reusable dialog that allows values to be returned. The subdialog executes in a new execution context with all variables and execution state initialized.

What is grammar in Vxml?

<grammar> Specifies the valid spoken utterances and corresponding string values returned in response to the utterances.


1 Answers

Two approaches are available: First, after collecting your input submit the form and the response should be a new VoiceXML document that plays your data.

Second, if your browser supports it (most do), you can use the Data element to make a request from within the VoiceXML form. The response needs to be XML. VoiceXML provides a way to walk the resulting DOM to get your data.

As for speaking the data, most browsers support the say-as element of SSML within a prompt. For most professional applications, the typically approach is to build a javascript library to assemble and play a set of recordings to play the time.

like image 153
Jim Rush Avatar answered Oct 15 '22 03:10

Jim Rush