gpt4 book ai didi

javascript - 使voiceXML读取服务器返回的结果

转载 作者:IT老高 更新时间:2023-10-28 23:26:04 27 4
gpt4 key购买 nike

我是 voiceXML 的新手,我想知道如何在发布后读取服务器返回的值。我希望voiceXML 读取服务器的响应。 According to voiceXML documentation ,我知道结果应该是XML。

这是我接收结果的 node.js/express.js 代码:

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>');
});

这是我成功接收到发布内容的截图:

enter image description here

这是显示我成功发送 XML 结果的屏幕截图: enter image description here

这是我的 voiceXML 文件:

<?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>

最佳答案

有两种方法可用:首先,在收集您的输入后提交表单,响应应该是一个播放数据的新 VoiceXML 文档。

其次,如果您的浏览器支持(大多数都支持),您可以使用 Data 元素从 VoiceXML 表单中发出请求。响应必须是 XML。 VoiceXML 提供了一种遍历生成的 DOM 以获取数据的方法。

说到数据,大部分浏览器都支持SSML的say-as元素。提示内。对于大多数专业应用程序,通常的做法是构建一个 javascript 库来组装和播放一组录音来播放时间。

关于javascript - 使voiceXML读取服务器返回的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33975098/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com