You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/Speech-Service/includes/how-to/speech-to-text-basics/speech-to-text-basics-javascript.md
+11-11Lines changed: 11 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ There are a few ways that you can initialize a [`SpeechConfig`](https://docs.mic
67
67
Let's take a look at how a [`SpeechConfig`](https://docs.microsoft.com/javascript/api/microsoft-cognitiveservices-speech-sdk/speechconfig?view=azure-node-latest) is created using a key and region. See the [region support](https://docs.microsoft.com/azure/cognitive-services/speech-service/regions#speech-sdk) page to find your region identifier.
Copy file name to clipboardExpand all lines: articles/cognitive-services/Speech-Service/includes/how-to/text-to-speech-basics/text-to-speech-basics-javascript.md
+34-33Lines changed: 34 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,11 @@ Additionally, depending on the target environment use one of the following:
For more information on `import`, see <ahref="https://javascript.info/import-export"target="_blank">export and import <spanclass="docon docon-navigate-external x-hidden-focus"></span></a>.
For more information on `require`, see <ahref="https://nodejs.org/en/knowledge/getting-started/what-is-require/"target="_blank">what is require? <spanclass="docon docon-navigate-external x-hidden-focus"></span></a>.
37
41
42
+
43
+
# [script](#tab/script)
44
+
45
+
Download and extract the <ahref="https://aka.ms/csspeech/jsbrowserpackage"target="_blank">JavaScript Speech SDK <spanclass="docon docon-navigate-external x-hidden-focus"></span></a> *microsoft.cognitiveservices.speech.sdk.bundle.js* file, and place it in a folder accessible to your HTML file.
> If you're targeting a web browser, and using the `<script>` tag; the `sdk` prefix is not needed. The `sdk` prefix is an alias we use to name our `import` or `require` module.
53
+
38
54
---
39
55
40
56
## Create a speech configuration
@@ -55,21 +71,22 @@ In this example, you create a [`SpeechConfig`](https://docs.microsoft.com/javasc
Next, you create a [`SpeechSynthesizer`](https://docs.microsoft.com/javascript/api/microsoft-cognitiveservices-speech-sdk/speechsynthesizer?view=azure-node-latest) object, which executes text-to-speech conversions and outputs to speakers, files, or other output streams. The [`SpeechSynthesizer`](https://docs.microsoft.com/javascript/api/microsoft-cognitiveservices-speech-sdk/speechsynthesizer?view=azure-node-latest) accepts as params the [`SpeechConfig`](https://docs.microsoft.com/javascript/api/microsoft-cognitiveservices-speech-sdk/speechconfig?view=azure-node-latest) object created in the previous step, and an [`AudioConfig`](https://docs.microsoft.com/javascript/api/microsoft-cognitiveservices-speech-sdk/audioconfig?view=azure-node-latest) object that specifies how output results should be handled.
66
82
67
-
To start, create an `AudioConfig` to automatically write the output to a `.wav` file using the `fromWavFileOutput()` static function.
83
+
To start, create an `AudioConfig` to automatically write the output to a `.wav` file using the `fromAudioFileOutput()` static function.
synthesizer.speakTextAsync("Synthesizing directly to speaker output.");
101
118
}
102
119
```
103
120
@@ -126,6 +143,7 @@ function synthesizeSpeech() {
126
143
result=> {
127
144
// Interact with the audio ArrayBuffer data
128
145
constaudioData=result.audioData;
146
+
console.log(`Audio data byte size: ${audioData.byteLength}.`)
129
147
},
130
148
error=>console.log(error));
131
149
}
@@ -145,14 +163,14 @@ To change the audio format, you use the `setSpeechSynthesisOutputFormat()` funct
145
163
146
164
There are various options for different file types depending on your requirements. Note that by definition, raw formats like `Raw24Khz16BitMonoPcm` do not include audio headers. Use raw formats only when you know your downstream implementation can decode a raw bitstream, or if you plan on manually building headers based on bit-depth, sample-rate, number of channels, etc.
147
165
148
-
In this example, you specify a high-fidelity RIFF format `Riff24Khz16BitMonoPcm` by setting the `SpeechSynthesisOutputFormat` on the `SpeechConfig` object. Similar to the example in the previous section, get the audio `ArrayBuffer` data and interact with it.
166
+
In this example, you specify a high-fidelity RIFF format `Riff24Khz16BitMonoPcm` by setting the `speechSynthesisOutputFormat` on the `SpeechConfig` object. Similar to the example in the previous section, get the audio `ArrayBuffer` data and interact with it.
@@ -184,30 +202,13 @@ First, create a new XML file for the SSML config in your root project directory,
184
202
185
203
Next, you need to change the speech synthesis request to reference your XML file. The request is mostly the same, but instead of using the `speakTextAsync()` function, you use `speakSsmlAsync()`. This function expects an XML string, so first you create a function to load an XML file and return it as a string.
186
204
187
-
# [import](#tab/import)
188
-
189
205
```javascript
190
-
import { readFileSync } from"fs";
191
-
192
206
functionxmlToString(filePath) {
193
207
constxml=readFileSync(filePath, "utf8");
194
208
return xml;
195
209
}
196
210
```
197
211
198
-
# [require](#tab/require)
199
-
200
-
```javascript
201
-
constfs=require("fs");
202
-
203
-
functionxmlToString(filePath) {
204
-
constxml=fs.readFileSync(filePath, "utf8");
205
-
return xml;
206
-
}
207
-
```
208
-
209
-
---
210
-
211
212
From here, the result object is exactly the same as previous examples.
0 commit comments