【问题标题】: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
【问题描述】:

我已经使用 MS Speech 服务 API 实现了一个聊天(MS Botframework sdk4 版本),用于文本到语音和语音到文本的转换。

这是我为实现此功能而引用的演示代码的链接。 https://github.com/Microsoft/ailab/tree/master/BuildAnIntelligentBot

只有在我单击客户端页面中的麦克风按钮时才会激活语音服务。因此,因此,我的机器人的介绍性消息无法启用文本到语音服务。因此,当我单击麦克风图标时,只有以下后续对话框启用语音。 如何在介绍性消息中也启用文本转语音?

【问题讨论】:

  • 展示你自己的实现。
  • 您的用户如何与机器人交互?通过网络聊天?
  • 是的,我正在通过网络聊天进行互动。

标签: 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,它仅可用于实际的用户交互。你如何做到这一点取决于你。也许您在连接聊天之前强制用户单击“运行机器人”按钮。

参考文献

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 2017-07-10
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多