在voicexml中选择的实现可以用menu,也可以用form。用menu方式实现参考上一篇文章,这里主要介绍一些form实现
可以使用from的option,也可以通过grammar来实现
1、option的实现(例子:http://www.optimsys.cz/support/examples/example07.php)
2、grammar的实现(http://www.w3.org/TR/voicexml20/)
可以使用from的option,也可以通过grammar来实现
1、option的实现(例子:http://www.optimsys.cz/support/examples/example07.php)
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<meta name="description" content="options and link example"/>
<meta name="author" content="OptimSys, s.r.o., Czech Republic (http://www.optimsys.cz)"/>
<meta name="copyright" content="free for any purpose"/>
<noinput> Hey, don't sleep! </noinput>
<catch event="exit">
<prompt> Exit! </prompt>
<exit/>
</catch>
<form id="start">
<field name="lunch">
<nomatch>
<prompt> I didn't understand you. Please choose from <enumerate/> </prompt>
</nomatch>
<help> Just say what you want for lunch. </help>
<prompt> What do you want for lunch? You can choose from <enumerate/> </prompt>
<option dtmf="1" value="ch"> chicken </option>
<option dtmf="2" value="p"> pizza </option>
<option dtmf="3" value="c"> cake </option>
<option dtmf="4" value="n"> nothing </option>
<filled>
<if cond="lunch=='ch'">
<prompt> You will have chicken for lunch. </prompt>
<prompt> I like chicken too. </prompt>
<elseif cond="lunch=='p'"/>
<prompt> You will have pizza for lunch. </prompt>
<prompt> Fan of Italian kitchen? </prompt>
<elseif cond="lunch=='c'"/>
<prompt> You will have cake for lunch. </prompt>
<prompt> You will be fat! </prompt>
<else/> <!-- lunch=='n' -->
<prompt> You will have nothing for lunch. </prompt>
<prompt> Diet? </prompt>
</if>
</filled>
</field>
</form>
2、grammar的实现(http://www.w3.org/TR/voicexml20/)
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/vxml
http://www.w3.org/TR/voicexml20/vxml.xsd">
<form id="tapered">
<block>
<prompt bargein="false">
Welcome to the ice cream survey.
</prompt>
</block>
<field name="flavor">
<grammar mode="voice" version="1.0" root="root">
<rule id="root" scope="public">
<one-of>
<item>vanilla </item>
<item>chocolate</item>
<item>strawberry</item>
</one-of>
</rule>
</grammar>
<prompt count="1">What is your favorite flavor?</prompt>
<prompt count="3">Say chocolate, vanilla, or strawberry.</prompt>
<help>Sorry, no help is available.</help>
</field>
</form>
</vxml>
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/vxml
http://www.w3.org/TR/voicexml20/vxml.xsd">
<meta name="en_inlinegrammar.vxml" content=""/>
<meta name="Author" content="HP"/>
<meta name="Date" content="September, 2005"/>
<meta name="Description"
content="This VoiceXML example is provided
as part of an HP OpenCall Media Platform
VoiceXML installation"/>
<meta name="Support" content="none"/>
<!-- Deactivate the barge in feature -->
<property name="bargein" value="false"/>
<form id="WhichDigit" scope="dialog">
<field name="digit">
<prompt>
Please say a digit.
</prompt>
<grammar mode="voice" version="1.0" root="root">
<rule id="root" scope="public">
<one-of>
<item> zero </item>
<item> one </item>
<item> two </item>
<item> three </item>
<item> four </item>
<item> five </item>
<item> six </item>
<item> seven </item>
<item> eight </item>
<item> nine </item>
</one-of>
</rule>
</grammar>
<filled>
<prompt>
Thanks, I think you said
<value expr="digit"/>.
</prompt>
</filled>
<!-- Message played if any error occured -->
<error count="1">
An error has occured.
</error>
<!-- Message played if the caller does not say anything -->
<noinput count="1">
Sorry, I did not hear anything. Try again.
<reprompt/>
</noinput>
<!-- Message played if the caller says something
that does not match -->
<nomatch count="1">
Sorry, I did not understand that. Try again.
<reprompt/>
</nomatch>
</field>
</form>
</vxml>