我已经实现了一个聊天(MS Botframework sdk4版本)使用MS语音服务应用程序接口的文本到语音和语音到文本的转换。
下面是我引用来实现此功能的演示代码的链接。https://github.com/Microsoft/ailab/tree/master/BuildAnIntelligentBot
语音服务仅在我单击客户端页面中的麦克风按钮时激活。因此,我的机器人的介绍性消息无法启用文本到语音服务。因此,当我单击麦克风图标时,只有以下后续对话框启用了语音功能。如何在介绍性消息上启用文本到语音转换?
发布于 2019-03-14 08:36:43
这几乎是不可能的。除非用户先发言(see the first paragraph after the first image),否则Web Chat不会发言。
您可以通过发送包含以下代码的假语音消息(在托管网络聊天的.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,它只对实际的用户交互可用。如何做到这一点取决于你自己。也许你强迫用户在连接聊天之前点击“运行机器人”按钮。
参考文献
https://stackoverflow.com/questions/55135274
复制相似问题