gpt4 book ai didi

java - Rivr VoiceXML for Java 中的 "Wait a second"消息

转载 作者:行者123 更新时间:2023-11-30 07:55:56 30 4
gpt4 key购买 nike

我需要在交互后立即播放“稍等...”消息。我需要这个,因为我必须在返回给用户之前执行一些耗时的任务。应用程序流程是:

1) 播放欢迎消息 (TTS)2)收集用户语音(Rivr语音录制交互)3) 播放“稍等一下”TTS 消息,因为语音和相关业务流程的处理非常耗时(需要几秒钟)4)【耗时任务】5) 播放 (TTS) 过程结果并说再见。

一切正常,但在耗时的任务以及过程的合成结果之后立即播放“稍等一下”消息(我的意思是,用户说话并且必须等待),即使在我的对话框代码中它放置在“耗时任务”之前。由于某种原因,Rivr 或 VoiceXML 引擎正在缓冲同时播放的两条消息(3 和 5)。

如何让 Rivr “刷新”第 3 步并在录制交互后立即播放“稍等一下”消息,以便用户知道他应该稍等一下?

最佳答案

在 VoiceXML 中提示排队

在 VoiceXML 中,每当执行提示时,它实际上都会被放入队列中。 VoiceXML 解释器仅在等待用户输入或退出时才会刷新提示队列(即播放它)。 Prompt Queueing and Input Collection 中详细描述了此行为。 VoiceXML W3C 文档的部分。

就您而言,您的提示在执行长时间操作之前已排队,并且仅在下一次交互期间播放。这是一种典型情况,经典 VoiceXML 解决方案在 Rivr 中具有同等功能。

解决方案 1:使用 fetchaudio 强制刷新提示队列

VoiceXML 规范规定提示队列将被刷新...

when the interpreter begins fetching a resource (such as a document) for which fetchaudio was specified. In this case the prompts queued before the fetchaudio are played to completion, and then, if the resource actually needs to be fetched (i.e. it is not unexpired in the cache), the fetchaudio is played until the fetch completes.

因此,为了确保播放提示,只需在<submit>上设置一个fetchaudio即可。用于获取长操作结果的元素。效果是播放“请稍候。”消息,然后循环播放 fetchaudio 中指定的文件,直到服务器返回结果。通常,您会使用声音来表明正在处理某些内容。

如果您不想在 VoiceXML 等待操作完成时听到任何声音,您可以提供一个静音的音频文件。另一个技巧是指定一个不存在的文件。这在某些 VoiceXML 平台下工作。 YMMV。

VoiceXML 可能如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<form id="form">
<block>
<prompt>Please wait a moment.</prompt>
<submit fetchaudio="/audio/fetch.wav" method="post" next="/long-operation" />
</block>
</form>
</vxml>

使用 Rivr,它是:

context.getFetchConfiguration().getDocumentFetchConfiguration()
.setFetchAudio("/audio/fetch.wav");

Message message = new Message("wait-message",
new SpeechSynthesis("Please wait a moment."));

DialogueUtils.doTurn(message, context);
performLongOperation();

解决方案2:插入人工等待状态

强制播放提示队列的另一个技巧是创建一个超时为 0 的虚拟交互。这会强制解释器播放消息。我们必须小心地在提示上禁用打断,否则 DTMF 输入可能会中断消息。以下是虚拟输入的示例:

<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.1" xmlns="http://www.w3.org/2001/vxml">
<form id="form">

<field name="dummy">
<property name="timeout" value="0ms" />
<grammar src="builtin:dtmf/digits" />
<prompt>Please wait a moment.</prompt>
<filled>
<goto nextitem="submit" />
</filled>
<noinput>
<goto nextitem="submit" />
</noinput>
<nomatch>
<goto nextitem="submit" />
</nomatch>
</field>

<block name="submit">
<submit fetchaudio="audio/fetch.wav" method="post" next="/long-operation" />
</block>

</form>
</vxml>

这是 Rivr 的等效项:

DtmfRecognition dummyRecognition = new DtmfRecognition(new GrammarReference("builtin:dtmf/digits"));

SpeechSynthesis message = new SpeechSynthesis("Please wait a moment.");

Interaction interaction = OutputTurns.interaction("wait-message")
.addPrompt(dummyRecognition, message).build();

DialogueUtils.doTurn(interaction, context);
performLongOperation();

如果您想在应用程序中重用此模式,您可以创建一个函数:

private void forcePlayMessage(VoiceXmlDialogueContext context,
String messageName,
AudioItem... audioItems)
throws Timeout, InterruptedException {
DtmfRecognition dummyRecognition = new DtmfRecognition(new GrammarReference("builtin:dtmf/digits"));
Interaction interaction = OutputTurns.interaction(messageName)
.addPrompt(dummyRecognition, audioItems).build();
DialogueUtils.doTurn(interaction, context);
}

如果操作很长,使用Java可能是明智的FutureTask类在后台处理您的请求,允许您的对话框每 X 秒向调用者发送消息,而不是阻塞 performLongOperation()

关于java - Rivr VoiceXML for Java 中的 "Wait a second"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32670820/

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