Skip to content

Commit eca390c

Browse files
authored
Update NodeJS Quickstarts/Samples to 1.11.0 (#570)
1 parent eb75898 commit eca390c

File tree

14 files changed

+384
-49
lines changed

14 files changed

+384
-49
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,7 @@ samples/cpp/windows/console/samples/sample
305305

306306
# macOS executables
307307
quickstart/cpp-macos/helloworld
308-
quickstart/text-to-speech/cpp-macos/helloworld
308+
quickstart/text-to-speech/cpp-macos/helloworld
309+
310+
# synthesized audio
311+
quickstart/**/text-to-speech/*.wav

quickstart/javascript/node/package-lock.json renamed to quickstart/javascript/node/from-file/package-lock.json

Lines changed: 19 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Quickstart: Synthesize speech in JavaScript on Node.js.
2+
3+
This sample demonstrates how to synthesize speech with the Speech SDK for JavaScript on Node.js.
4+
5+
## Prerequisites
6+
7+
* A subscription key for the Speech service. See [Try the speech service for free](https://docs.microsoft.com/azure/cognitive-services/speech-service/get-started).
8+
* A [Node.js](https://nodejs.org) compatible device.
9+
10+
## Prepare the sample
11+
12+
* [Download the sample code to your development PC.](/README.md#get-the-samples)
13+
* Open a command prompt at the quickstart directory, and run `npm install` to install the dependencies of the quickstart.
14+
This will place the Speech SDK library in the `node_modules` directory.
15+
* Update the `index.js` file with your configuration:
16+
* Replace the string `YourSubscriptionKey` with your own subscription key.
17+
* Replace the string `YourServiceRegion` with the service region of your subscription.
18+
For example, replace with `westus` if you are using the 30-day free trial subscription.
19+
* Replace the string `YourAudioFile.wav` with a path you desire.
20+
21+
## Run the sample
22+
23+
Execute `node index.js` from the location where you have downloaded this quickstart.
24+
25+
## References
26+
27+
* [Speech SDK API reference for JavaScript](https://aka.ms/csspeech/javascriptref)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
(function() {
5+
// <code>
6+
"use strict";
7+
8+
// pull in the required packages.
9+
var sdk = require("microsoft-cognitiveservices-speech-sdk");
10+
var readline = require("readline");
11+
12+
// replace with your own subscription key,
13+
// service region (e.g., "westus"), and
14+
// the name of the file you save the synthesized audio.
15+
var subscriptionKey = "YourSubscriptionKey";
16+
var serviceRegion = "YourServiceRegion"; // e.g., "westus"
17+
var filename = "YourAudioFile.wav";
18+
19+
// we are done with the setup
20+
21+
// now create the audio-config pointing to our stream and
22+
// the speech config specifying the language.
23+
var audioConfig = sdk.AudioConfig.fromAudioFileOutput(filename);
24+
var speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
25+
26+
// create the speech synthesizer.
27+
var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);
28+
29+
var rl = readline.createInterface({
30+
input: process.stdin,
31+
output: process.stdout
32+
});
33+
34+
rl.question("Type some text that you want to speak...\n> ", function (text) {
35+
rl.close();
36+
// start the synthesizer and wait for a result.
37+
synthesizer.speakTextAsync(text,
38+
function (result) {
39+
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
40+
console.log("synthesis finished.");
41+
} else {
42+
console.error("Speech synthesis canceled, " + result.errorDetails +
43+
"\nDid you update the subscription info?");
44+
}
45+
synthesizer.close();
46+
synthesizer = undefined;
47+
},
48+
function (err) {
49+
console.trace("err - " + err);
50+
synthesizer.close();
51+
synthesizer = undefined;
52+
});
53+
console.log("Now synthesizing to: " + filename);
54+
});
55+
// </code>
56+
57+
}());
58+

quickstart/javascript/node/text-to-speech/package-lock.json

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"private": true,
3+
"name": "speech-sdk-quickstart-node-tts",
4+
"version": "1.0.0",
5+
"description": "Text-to-speech quickstart for the Microsoft Speech SDK on Node.js",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "Microsoft",
11+
"license": "MIT",
12+
"dependencies": {
13+
"https-proxy-agent": "^3.0.0",
14+
"microsoft-cognitiveservices-speech-sdk": "^1.11.0",
15+
"readline": "^1.3.0"
16+
}
17+
}

samples/js/node/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# JavaScript Speech Recognition and Translation Sample for Node.js
1+
# JavaScript Speech Recognition, Synthesis and Translation Sample for Node.js
22

3-
This sample demonstrates how to recognize speech with the Speech SDK for JavaScript on Node.js. It is based on the [Microsoft Cognitive Services Speech SDK for JavaScript](https://aka.ms/csspeech/npmpackage).
3+
This sample demonstrates how to recognize and synthesis speech with the Speech SDK for JavaScript on Node.js. It is based on the [Microsoft Cognitive Services Speech SDK for JavaScript](https://aka.ms/csspeech/npmpackage).
44
See [this article](https://docs.microsoft.com/azure/cognitive-services/speech-service/quickstart-js-node) for introductory information on the Speech SDK for JavaScript on Node.js.
55

66
## Prerequisites
@@ -24,10 +24,10 @@ See [this article](https://docs.microsoft.com/azure/cognitive-services/speech-se
2424

2525
## Run the sample
2626

27-
The sample demonstrates the speech, intent, and translation recognizers. You can start them individually by calling:
27+
The sample demonstrates the speech, intent, and translation recognizers, as well as speech synthesizer. You can start them individually by calling:
2828

2929
```shell
30-
node index.js [speech|intent|translate] {filename}
30+
node index.js [speech|intent|translate|synthesis] {filename}
3131
```
3232

3333
## References

samples/js/node/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
var speech = require("./speech");
1313
var intent = require("./intent");
1414
var translate = require("./translation");
15+
var synthesis = require("./synthesis");
1516

1617
function openPushStream(filename) {
1718
// create the push stream we need for the speech sdk.
@@ -42,6 +43,11 @@
4243
console.log("Now translating from: " + settings.filename);
4344
translate.main(settings, openPushStream(settings.filename));
4445
break;
46+
47+
case "synthesis":
48+
console.log("Now synthesizing to: " + settings.filename);
49+
synthesis.main(settings, settings.filename);
50+
break;
4551

4652
case "speech":
4753
default:
@@ -51,7 +57,7 @@
5157
}
5258
}
5359
else {
54-
console.log("usage: index.js [speech|intent|translate] {filename}");
60+
console.log("usage: index.js [speech|intent|translate|synthesis] {filename}");
5561
}
5662
}());
5763

0 commit comments

Comments
 (0)