如何为sdk v4 Bot的消息添加语音



如何添加session.say(…..)等功能,该功能适用于使用v4-sdk构建的机器人的Cortana等语音通道。

这是v3机器人的好文档

我在哪里可以找到类似的v4机器人?

您包含的链接适用于DirectLinev3,它是DirectLine的最新版本。

但是,我相信您从这个V3文档中获得了session.say命令。不幸的是,它没有一个V4版本。

但是,大多数Message类型都有一个speakssml属性(JS/C#),您可以使用它来发送将要说的文本。

它的工作原理是一样的。不使用(来自V3文档):

JS v3

var msg = new builder.Message(session)
.text('This is the text that will be displayed')
.speak('This is the text that will be spoken.');
session.send(msg).endDialog();

C#v3

Activity msg = activity.CreateReply("This is the text that will be displayed."); 
reply.Speak = "This is the text that will be spoken.";
reply.InputHint = InputHints.AcceptingInput;
await connector.Conversations.ReplyToActivityAsync(reply);

你会使用:

JS v4

var msg = MessageFactory.text({ text: "This is the text that will be displayed", ssml: "This is the text that will be spoken" });
await context.SendActivity(msg);

C#v4

var msg = MessageFactory.Text(text: "This is the text that will be displayed", ssml: "This is the text that will be spoken");
await context.SendActivity(msg);

await行可能会有所不同,这取决于您在机器人中的使用位置/方式。

请注意,要测试语音,还有一些额外的步骤需要设置。你可以在这里找到参考资料:

  • 在Emulator中使用语音
  • 在网络聊天中使用语音
  • 在浏览器中使用语音,问题

最后,这里有一个使用Cortana和语音的示例机器人。具体来说,您可以在这里看到它是如何使用MessageFactory.text的。

Cortana关于为V3或V4机器人添加语音的主题文档:https://learn.microsoft.com/en-us/cortana/skills/adding-speech

最新更新