【问题标题】:How to enable text to speech service on introduction message in MS BOT FRAMEWORK sdk4如何在 MS BOT FRAMEWORK sdk4 中的介绍消息上启用文本到语音服务
【发布时间】:2019-03-13 05:53:50
【问题描述】:
【问题讨论】:
标签:
c#
botframework
azure-cognitive-services
【解决方案1】:
这是几乎可能的。 Web Chat 设计为除非用户先发言 (see the first paragraph after the first image),否则不会发言。
您可以通过使用以下代码(在托管网络聊天的 .html 文件中)发送虚假语音消息来欺骗网络聊天,使其认为用户已经说过话来解决此问题:
<script>
// Must create store so we can send command
const store = window.WebChat.createStore();
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ secret: 'YourBotSecret' }),
// Add speech capability
webSpeechPonyfillFactory: window.WebChat.createBrowserWebSpeechPonyfillFactory(),
store
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
// When mic button is clicked, send message as though user has spoken
// Note: 'test' will not be displayed at all to the user. You can replace it with anything.
document.querySelector('[title="Speak"]').addEventListener('click', () => {
store.dispatch({
type: 'WEB_CHAT/START_SPEAKING',
payload: { text: 'test' }
});
});
// Programatically click the mic button
document.querySelector('[title="Speak"]').click();
// Programatically click the mic button back off
window.setTimeout(() => document.querySelector('[title="Speak"]').click(), 500);
// Stop listening
document.querySelector('[title="Speak"]').removeEventListener('click', () => {
store.dispatch({
type: 'WEB_CHAT/START_SPEAKING',
payload: { text: 'test' }
});
});
</script>
重要提示: Chrome doesn't like this:
解决此问题的唯一方法是强制用户首先与网站进行交互。 Any of these 交互工作。一个关键点是事件必须有isTrusted,它仅可用于实际的用户交互。你如何做到这一点取决于你。也许您在连接聊天之前强制用户单击“运行机器人”按钮。
参考文献