需要C#代码才能产生以下TwiML输出

问题描述

想在收集中嵌套“说”指令,但是我想在“说”指令上使用.Emphasis,.Break和.Prosody等修饰符。在C#中似乎没有办法做到这一点。我想要的结果TwiML代码如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="/voice/processmygather" method="GET">
<Say> Hi
<break strength="x-weak" time="100ms"/>
<emphasis level="moderate">Words to emphasize</emphasis>
<p>Words to speak</p>
<prosody pitch="-10%" rate="85%" volume="-6dB">Words to speak</prosody>
<s>Words to speak</s>
<say-as interpret-as="spell-out">Words to speak</say-as>
<sub alias="alias">Words to be substituted</sub>
<w>Words to speak</w>
</Say>
</Gather>
<Say>We didn't receive any input. Goodbye!</Say>
</Response>

在C#中,我可以创建一个“说”动词对象并将其修改为类似于上面的形式,但是不能将其嵌套嵌套在聚集中,以便用户可以通过响应打断发言并继续处理聚集。

var response = new VoiceResponse();
var mygather = new Gather(input: bothDtmfAndSpeech,action: new Uri("/voice/processmygather",UriKind.Relative),speechModel: Gather.SpeechModelEnum.NumbersAndCommands,enhanced: true,hints: hintchoices,bargeIn: true,speechTimeout: "auto",numDigits: 1);
var mysay = new Say("Hi",voice: "Polly.Joanna");
mysay.Break(strength: "x-weak",time: "100ms");
mysay.Emphasis("Words to emphasize",level: "moderate");
mysay.P("Words to speak");
mysay.phoneme("Words to speak",alphabet: "x-sampa",ph: "pɪˈkɑːn");
mysay.Prosody("Words to speak",pitch: "-10%",rate: "85%",volume: "-6dB");
mysay.SayAs("Words to speak",interpretAs: "spell-out",role: "yyyymmdd");

/* There seems to be no way to do the following command */
response.Append(mygather.mysay);

/* I can only do the following */
response.Append(mysay); // plays the entire say
response.Append(mygather); // only after playing entire say am I able to gather

/* I seem to able to do only the following with limited markup capability */
response.Append(mygather.Say("Here is something I want to say but have little ability to fine tune the say with .Emphasis .Break or .Prosody controls"));

因此,是否可以在收集中用我想要的所有控件标记我的“说”(非常类似于上面的顶部代码块),将其保存到XML文件,然后将响应对象指向该XML文件,并且仍然能够在我的C#应用​​程序中捕获用户的语音或数字响应?

解决方法

决定发布后人的答案,以防其他人遇到类似问题并在此页面上发生。

在收集对象中包含say对象的正确方法是:

/* include the marked up mysay object within the mygather object */
mygather.Append(mysay); 

/* speak the marked up mysay twiML while waiting an answer */
response.Append(mygather); 

另一个警告是,如果这个谜题指定了-Neural声音,它将不会播放某些标记的标签,例如.Emphasis。

下表显示了标记标记的兼容性: https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html

感谢用户“ tychon”(在所讨论的评论中)提供了提示,以帮助我找到答案。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...