Skip to content

Commit

Permalink
Add: stop continuous recognition button
Browse files Browse the repository at this point in the history
연속 인식을 중지하는 버튼과 로직을 추가
  • Loading branch information
nuatmochoi committed Oct 10, 2020
1 parent fc117d4 commit 662f00e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</head>
<body>
<button id="start_stt">STT 시작하기</button>
<button id="stop_stt">STT 중지하기</button>
</body>
<script src="index.js"></script>
</html>
23 changes: 5 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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}`);
Expand All @@ -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();
});
});

0 comments on commit 662f00e

Please sign in to comment.