Skip to content

Commit 1ea4310

Browse files
authored
Correct from-file JS browser quickstart (#889)
#884
1 parent ee8139f commit 1ea4310

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

quickstart/javascript/browser/from-file/index.html

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ <h1 style="font-weight:500;">Speech Recognition Speech SDK not found (microsoft.
2424
<td align="right">Region</td>
2525
<td><input id="serviceRegion" type="text" size="40" value="YourServiceRegion"></td>
2626
</tr>
27+
<tr>
28+
<td align="right">File to Recognize</td>
29+
<td>
30+
<input type="file" id="filePicker" accept=".wav" />
31+
</td>
32+
</tr>
2733
<tr>
2834
<td></td>
2935
<td><button id="startRecognizeOnceAsyncButton">Start recognition</button></td>
@@ -65,6 +71,7 @@ <h1 style="font-weight:500;">Speech Recognition Speech SDK not found (microsoft.
6571
// status fields and start button in UI
6672
var phraseDiv;
6773
var startRecognizeOnceAsyncButton;
74+
var filePicker, audioFile;
6875

6976
// subscription key and region for speech services.
7077
var subscriptionKey, serviceRegion;
@@ -77,6 +84,11 @@ <h1 style="font-weight:500;">Speech Recognition Speech SDK not found (microsoft.
7784
subscriptionKey = document.getElementById("subscriptionKey");
7885
serviceRegion = document.getElementById("serviceRegion");
7986
phraseDiv = document.getElementById("phraseDiv");
87+
filePicker = document.getElementById("filePicker");
88+
filePicker.addEventListener("change", function () {
89+
audioFile = filePicker.files[0];
90+
startRecognizeOnceAsyncButton.disabled = false;
91+
});
8092

8193
startRecognizeOnceAsyncButton.addEventListener("click", function () {
8294
startRecognizeOnceAsyncButton.disabled = true;
@@ -95,7 +107,7 @@ <h1 style="font-weight:500;">Speech Recognition Speech SDK not found (microsoft.
95107
}
96108

97109
speechConfig.speechRecognitionLanguage = "en-US";
98-
var audioConfig = SpeechSDK.AudioConfig.fromDefaultMicrophoneInput();
110+
var audioConfig = SpeechSDK.AudioConfig.fromWavFileInput(audioFile);
99111
recognizer = new SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
100112

101113
recognizer.recognizeOnceAsync(

0 commit comments

Comments
 (0)