【发布时间】:2020-11-11 18:25:50
【问题描述】:
想在集合中嵌套“说”指令,但我想在“说”指令上使用 .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”动词对象并将其修改为如上所示,但不能将其安排为嵌套在一个集合中,以便用户可以通过响应中断该说并继续处理收集。
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# 应用程序中捕获用户的语音或数字响应?
【问题讨论】:
-
Gather类有一个Say方法,这可能是你想要的。 -
Gather也有一个Append方法来添加任意 TwiML 元素作为子元素。似乎您可以致电mygather.Append(mysay)来实现您想要的,但我从未与 Twilio 合作过,也无法进行测试。 twilio.com/docs/libraries/reference/twilio-csharp/5.13.5/… -
Ackdari - 是的,Gather 类确实有一个 Say 方法,正如我所指出的。问题是它几乎没有方法可以像你认为它所基于的 Say 动词对象那样塑造 Say。
-
tychon - 我会研究那个收集方法,看看它是否有效。
-
tychon - 谢谢,gather 上的 Append 方法似乎有效!
标签: c# twilio-twiml twilio-programmable-voice