Microsoft Azure Web Chat,从其他功能触发麦克风

时间:2017-11-10 15:07:51

标签: node.js speech-recognition botframework voice-recognition

我使用Microsoft Bot Framework为客户端创建机器人。即称为WebChat。我还添加了Speech SpeechRecognizer。但是,我正在尝试在录制短语时触发麦克风。

我无法在Microsoft中找到执行此操作的功能。所以我添加了自己的语音识别器,每秒调用一次,一旦调用该短语,我想从认知服务中调用麦克风功能。

我如何实现这一目标?

我从here

获得了语音识别器

我写的用来识别短语的是:

function startDictation() {

            if (window.hasOwnProperty('webkitSpeechRecognition')) {

                var recognition = new webkitSpeechRecognition();

                recognition.continuous = false;
                recognition.interimResults = false;

                recognition.lang = "en-US";
                recognition.start();

                recognition.onresult = function (e) {
                    var foundText = e.results[0][0].transcript;
                    console.log(foundText);
                    if (foundText == "hello hello") {
                        console.log("found text");
                        //call cognitive service mic function
                        recognition.stop();
                    }
                    else {
                        console.log("text not found");
                        recognition.stop();
                        startDictation();
                    }
                };

                recognition.onerror = function (e) {
                    console.log("found error", e);
                    recognition.stop();
                }

            }
        }

如果有任何信息丢失或错过,请告诉我。

更多: enter image description here

1 个答案:

答案 0 :(得分:1)

我尝试在https://github.com/Microsoft/BotFramework-WebChat/blob/master/src/CognitiveServices/SpeechRecognition.ts#L72startRecognizing()类中使用SpeechRecognizer函数来触发识别功能。但是,我发现只有点击麦克风项目,我才能使用startRecognizing()功能识别语音。

目前您可以尝试使用一种技巧解决方法:

我检查了麦克风项目,并尝试在js中删除它的click事件,这完全可以识别我的演讲。

enter image description here

您可以尝试将以下js代码段与jQuery一起使用:

$('.wc-mic').trigger("click")

希望它有所帮助。