【问题标题】:Need C# code to result in the following TwiML output需要 C# 代码以产生以下 TwiML 输出
【发布时间】: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


【解决方案1】:

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

在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。

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

感谢用户“tychon”(上面有问题的 cmets)提供了帮助我找到答案的提示。

【讨论】:

    猜你喜欢
    • 2016-04-17
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多