如何在 Botframework V4 和 Webchat 上启动带麦克风的机器人

How to Start a Bot with the Microphone On on Botframework V4 and Webchat

我正在构建一个机器人,它需要从一开始就与用户进行语音交互。
换句话说,用户应该会听到欢迎消息,并且他们可以立即与机器人对话,而无需单击麦克风图标。
我正在使用机器人框架 V4 和最新版本的 webchat.js
用于启动机器人的代码片段如下:

  (async function () {

        const searchParams = new URLSearchParams(window.location.search);

        //Speech Service Token Generation
        const subscriptionKey = 'XXXX';
        const region = 'brazilsouth';
        let webSpeechPonyfillFactory;

        //Speech Service Setting
        webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({
            credentials: {
                authorizationToken: speechAuthToken,
                region: region
            }
        });

        //Direct-Line BotToken Generation
        const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', { method: 'POST', headers: { Authorization: 'Bearer ' + 'XXXXX' } });
        const { token } = await res.json();
        //***
        //Bot Service Setting
        window.WebChat.renderWebChat({
            directLine: window.WebChat.createDirectLine({ token }),
            store,
            userID: "User",
            styleOptions,
            locale: 'pt-BR',
            selectVoice: (voices, activity) =>
                activity.locale === 'pt-BR'
                    ? voices.find(({ name }) => /Daniel/iu.test(name))
                    : voices.find(({ name }) => /Daniel/iu.test(name)) ||
                    voices.find(({ name }) => /Daniel/iu.test(name)),
            webSpeechPonyfillFactory
        }, document.getElementById('botBody'));
        document.querySelector('#botBody > *').focus();

        var mainTag = chatbot.getElementsByClassName('main')[0];
        mainTag.style.borderTop = chatbot.dataset.cbBorder;
    })().catch(err => console.error(err));

我怎样才能做到这一点?感谢

遗憾的是,目前 Web Chat 不支持此功能。从技术上讲,浏览器首先会阻止在没有某种用户手势/语音输入的情况下启动的任何语音。

正在开发以缓解网络聊天中的此问题(问题 #2211),但是没有具体的预计到达时间。此更新目前已推送到下一个版本 R9,但有迹象表明它可能是 R10 的一部分。换句话说,考虑部署 "subject to change".

如果这对您很重要,请考虑添加您对上述 link 的兴趣(也可能对此 issue 感兴趣)。

希望得到帮助!