需要 C# 代码来生成以下 TwiML 输出

Need C# code to result in the following TwiML output

想在集合中嵌套“Say”指令,但我想在“Say”指令上使用修饰符,如 .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# 中,我可以创建一个“Say”动词对象并将其修改为如上所示,但不能将其安排为嵌套在一个集合中,以便用户可以通过响应打断 say 并继续处理收集。

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"));

所以,是否可以在一个集合中用我想要的所有控件标记我的 Say(很像上面的顶部代码块),将其保存到 XML 文件,然后指向XML 文件的响应对象,并且仍然能够在我的 C# 应用程序中捕获用户的语音或数字响应?

决定 post 对 post 的回答,以防其他人有类似的问题并发生在这个页面上。

在 gather 对象中包含 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); 

另一个警告是,如果 mysay 指定了 -Neural 语音,它将不会播放一些标记的标签,如 .Emphasis。

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

感谢用户“tychon”(以上评论中的问题)提供了帮助我找到答案的提示。