扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共9页)
创建一个 VXML 文件的原型
首先要开发 VXML 文件。不要打开一个 IDE 并开始编写 Java 代码,而是启动一个文本编辑器,忍住立即添加 package
和 import
语句的渴望。构建一个简单的 VXML 文件,就像本文前面给出的示例那样。
例如,清单 2 是又一个非常基础的 VXML 文件。它是一个语音识别 VXML 文件,接入一个恰当的设备并提供某些关于呼叫选择的注释。
<?xml version="1.0" encoding="UTF-8"?> <vxml version="2.1"> <form id="MainMenu"> <field name="instrument"> <prompt>What is your favorite musical instrument?</prompt> <!-- Insert an inline grammar --> <grammar type="text/gsl"> [guitar mandolin dobro (violin fiddle) banjo] </grammar> <!-- Handle the case when they give no answer --> <noinput> Did you say something? I didn't hear you. <reprompt /> </noinput> <!-- Handle the case when no match is found --> <nomatch> I suppose that's OK, but it's not on my top five. Want to try again? <reprompt /> </nomatch> </field> <!-- Handle the various options. --> <filled namelist="instrument"> <if cond="instrument == 'guitar'"> <prompt>That's right! Hang up and go practice.</prompt> <elseif cond="instrument == 'mandolin'" /> <prompt>Nice... and only four strings to keep in tune.</prompt> <elseif cond="instrument == 'dobro'" /> <prompt>Boy, that's no fun to learn, is it?</prompt> <elseif cond="instrument == 'violin'" /> <prompt>We call that a fiddle, Mr. Fancy Pants.</prompt> <elseif cond="instrument == 'fiddle'" /> <prompt>Does playing classical music on a fiddle make it a violin?</prompt> <elseif cond="instrument == 'banjo'" /> <prompt>Wow, I hope you live alone.</prompt> </if> </filled> </form> </vxml> |
编写这个 VXML、保存它、将它上传到 ISP,然后为它分配一个号码。只有在您完成所有这些步骤后 ―― 确保您的 VXML 正常工作,才是准备好了,可以开始 考虑编写 Java 代码。
如果您直接跳到 Java,那么很可能会导致输出中出错,代码中也会出错。结果是要在一个 Web 框架内尝试同步调试一个 VXML 文件(XML)和一个 Servlet(Java),这种调试极其艰难。不要添加所有这些变量(没有双关的意思),务必从一个可正常工作的 VXML 文件入手。然后 准备运行 Java 代码。
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。