From 662f00eff1b40bb1c6865aa15f47350097690a6a Mon Sep 17 00:00:00 2001 From: nuatmochoi Date: Sat, 10 Oct 2020 13:47:11 +0900 Subject: [PATCH] Add: stop continuous recognition button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 연속 인식을 중지하는 버튼과 로직을 추가 --- index.html | 1 + index.js | 23 +++++------------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/index.html b/index.html index 83d505d..46a4f5f 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ + diff --git a/index.js b/index.js index 29f5890..4e5677e 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ const start_stt = this.document.getElementById('start_stt'); +const stop_stt = this.document.getElementById('stop_stt'); start_stt.addEventListener('click', function () { const speechConfig = SpeechSDK.SpeechConfig.fromSubscription( 'fa50041df8f34ef3a14a9ef22b910602', @@ -8,12 +9,6 @@ start_stt.addEventListener('click', function () { const audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput(); const recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig); - // const recognizer = new SpeechSDK.SpeechRecognizer(speechConfig); - - // recognizer.recognizing = (s, e) => { - // console.log(`RECOGNIZING: Text=${e.result.text}`); - // }; - recognizer.recognized = (s, e) => { if (e.result.reason == SpeechSDK.ResultReason.RecognizedSpeech) { console.log(`RECOGNIZED: Text=${e.result.text}`); @@ -22,22 +17,14 @@ start_stt.addEventListener('click', function () { } }; - recognizer.canceled = (s, e) => { - console.log(`CANCELED: Reason=${e.reason}`); - - if (e.reason == SpeechSDK.CancellationReason.Error) { - console.log(`"CANCELED: ErrorCode=${e.errorCode}`); - console.log(`"CANCELED: ErrorDetails=${e.errorDetails}`); - console.log('CANCELED: Did you update the subscription info?'); - } - - recognizer.stopContinuousRecognitionAsync(); - }; - recognizer.sessionStopped = (s, e) => { console.log('\n Session stopped event.'); recognizer.stopContinuousRecognitionAsync(); }; recognizer.startContinuousRecognitionAsync(); + + stop_stt.addEventListener('click', function () { + recognizer.stopContinuousRecognitionAsync(); + }); });