Skip to content

Commit

Permalink
Update NodeJS Quickstarts/Samples to 1.11.0 (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
yulin-li authored Apr 2, 2020
1 parent eb75898 commit eca390c
Show file tree
Hide file tree
Showing 14 changed files with 384 additions and 49 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,7 @@ samples/cpp/windows/console/samples/sample

# macOS executables
quickstart/cpp-macos/helloworld
quickstart/text-to-speech/cpp-macos/helloworld
quickstart/text-to-speech/cpp-macos/helloworld

# synthesized audio
quickstart/**/text-to-speech/*.wav
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
27 changes: 27 additions & 0 deletions quickstart/javascript/node/text-to-speech/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Quickstart: Synthesize speech in JavaScript on Node.js.

This sample demonstrates how to synthesize speech with the Speech SDK for JavaScript on Node.js.

## Prerequisites

* 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).
* A [Node.js](https://nodejs.org) compatible device.

## Prepare the sample

* [Download the sample code to your development PC.](/README.md#get-the-samples)
* Open a command prompt at the quickstart directory, and run `npm install` to install the dependencies of the quickstart.
This will place the Speech SDK library in the `node_modules` directory.
* Update the `index.js` file with your configuration:
* Replace the string `YourSubscriptionKey` with your own subscription key.
* Replace the string `YourServiceRegion` with the service region of your subscription.
For example, replace with `westus` if you are using the 30-day free trial subscription.
* Replace the string `YourAudioFile.wav` with a path you desire.

## Run the sample

Execute `node index.js` from the location where you have downloaded this quickstart.

## References

* [Speech SDK API reference for JavaScript](https://aka.ms/csspeech/javascriptref)
58 changes: 58 additions & 0 deletions quickstart/javascript/node/text-to-speech/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

(function() {
// <code>
"use strict";

// pull in the required packages.
var sdk = require("microsoft-cognitiveservices-speech-sdk");
var readline = require("readline");

// replace with your own subscription key,
// service region (e.g., "westus"), and
// the name of the file you save the synthesized audio.
var subscriptionKey = "YourSubscriptionKey";
var serviceRegion = "YourServiceRegion"; // e.g., "westus"
var filename = "YourAudioFile.wav";

// we are done with the setup

// now create the audio-config pointing to our stream and
// the speech config specifying the language.
var audioConfig = sdk.AudioConfig.fromAudioFileOutput(filename);
var speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);

// create the speech synthesizer.
var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig);

var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

rl.question("Type some text that you want to speak...\n> ", function (text) {
rl.close();
// start the synthesizer and wait for a result.
synthesizer.speakTextAsync(text,
function (result) {
if (result.reason === sdk.ResultReason.SynthesizingAudioCompleted) {
console.log("synthesis finished.");
} else {
console.error("Speech synthesis canceled, " + result.errorDetails +
"\nDid you update the subscription info?");
}
synthesizer.close();
synthesizer = undefined;
},
function (err) {
console.trace("err - " + err);
synthesizer.close();
synthesizer = undefined;
});
console.log("Now synthesizing to: " + filename);
});
// </code>

}());

136 changes: 136 additions & 0 deletions quickstart/javascript/node/text-to-speech/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions quickstart/javascript/node/text-to-speech/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"private": true,
"name": "speech-sdk-quickstart-node-tts",
"version": "1.0.0",
"description": "Text-to-speech quickstart for the Microsoft Speech SDK on Node.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Microsoft",
"license": "MIT",
"dependencies": {
"https-proxy-agent": "^3.0.0",
"microsoft-cognitiveservices-speech-sdk": "^1.11.0",
"readline": "^1.3.0"
}
}
8 changes: 4 additions & 4 deletions samples/js/node/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JavaScript Speech Recognition and Translation Sample for Node.js
# JavaScript Speech Recognition, Synthesis and Translation Sample for Node.js

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).
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).
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.

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

## Run the sample

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

```shell
node index.js [speech|intent|translate] {filename}
node index.js [speech|intent|translate|synthesis] {filename}
```

## References
Expand Down
8 changes: 7 additions & 1 deletion samples/js/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
var speech = require("./speech");
var intent = require("./intent");
var translate = require("./translation");
var synthesis = require("./synthesis");

function openPushStream(filename) {
// create the push stream we need for the speech sdk.
Expand Down Expand Up @@ -42,6 +43,11 @@
console.log("Now translating from: " + settings.filename);
translate.main(settings, openPushStream(settings.filename));
break;

case "synthesis":
console.log("Now synthesizing to: " + settings.filename);
synthesis.main(settings, settings.filename);
break;

case "speech":
default:
Expand All @@ -51,7 +57,7 @@
}
}
else {
console.log("usage: index.js [speech|intent|translate] {filename}");
console.log("usage: index.js [speech|intent|translate|synthesis] {filename}");
}
}());

Loading

0 comments on commit eca390c

Please sign in to comment.