科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道在Java Web框架中创建VoiceXML页面

在Java Web框架中创建VoiceXML页面

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

对于绝大多数 Web 开发人员来说,输出 HTML、XHTML 乃至 XML 是一项微不足道的任务,它只不过是创建和部署 Web 应用程序的常规流程。从显示 Internet 页面到应答电话呼叫看似一个巨大的飞跃,但实际并非如此。在这篇文章中,您将看到相同的技术如何帮助您动态创建 Web 页面以

作者:中国IT实验室 来源:中国IT实验室 2007年9月22日

关键字: VoiceXML Web框架 java

  • 评论
  • 分享微博
  • 分享邮件

在本页阅读全文(共9页)

创建一个 VXML 文件的原型

    首先要开发 VXML 文件。不要打开一个 IDE 并开始编写 Java 代码,而是启动一个文本编辑器,忍住立即添加 packageimport 语句的渴望。构建一个简单的 VXML 文件,就像本文前面给出的示例那样。

    例如,清单 2 是又一个非常基础的 VXML 文件。它是一个语音识别 VXML 文件,接入一个恰当的设备并提供某些关于呼叫选择的注释。


清单 2. 另外一个基本的 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领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章