From eca390c47cc4da0e15528b3599e0faeba0673d40 Mon Sep 17 00:00:00 2001 From: Yulin Li Date: Thu, 2 Apr 2020 17:01:45 +0800 Subject: [PATCH] Update NodeJS Quickstarts/Samples to 1.11.0 (#570) --- .gitignore | 5 +- .../javascript/node/{ => from-file}/README.md | 0 .../javascript/node/{ => from-file}/index.js | 0 .../node/{ => from-file}/package-lock.json | 40 +++--- .../node/{ => from-file}/package.json | 0 .../javascript/node/text-to-speech/README.md | 27 ++++ .../javascript/node/text-to-speech/index.js | 58 ++++++++ .../node/text-to-speech/package-lock.json | 136 ++++++++++++++++++ .../node/text-to-speech/package.json | 17 +++ samples/js/node/README.md | 8 +- samples/js/node/index.js | 8 +- samples/js/node/package-lock.json | 45 +++--- samples/js/node/package.json | 3 +- samples/js/node/synthesis.js | 86 +++++++++++ 14 files changed, 384 insertions(+), 49 deletions(-) rename quickstart/javascript/node/{ => from-file}/README.md (100%) rename quickstart/javascript/node/{ => from-file}/index.js (100%) rename quickstart/javascript/node/{ => from-file}/package-lock.json (79%) rename quickstart/javascript/node/{ => from-file}/package.json (100%) create mode 100644 quickstart/javascript/node/text-to-speech/README.md create mode 100644 quickstart/javascript/node/text-to-speech/index.js create mode 100644 quickstart/javascript/node/text-to-speech/package-lock.json create mode 100644 quickstart/javascript/node/text-to-speech/package.json create mode 100644 samples/js/node/synthesis.js diff --git a/.gitignore b/.gitignore index 651ee37bb..e7e926e36 100644 --- a/.gitignore +++ b/.gitignore @@ -305,4 +305,7 @@ samples/cpp/windows/console/samples/sample # macOS executables quickstart/cpp-macos/helloworld -quickstart/text-to-speech/cpp-macos/helloworld \ No newline at end of file +quickstart/text-to-speech/cpp-macos/helloworld + +# synthesized audio +quickstart/**/text-to-speech/*.wav \ No newline at end of file diff --git a/quickstart/javascript/node/README.md b/quickstart/javascript/node/from-file/README.md similarity index 100% rename from quickstart/javascript/node/README.md rename to quickstart/javascript/node/from-file/README.md diff --git a/quickstart/javascript/node/index.js b/quickstart/javascript/node/from-file/index.js similarity index 100% rename from quickstart/javascript/node/index.js rename to quickstart/javascript/node/from-file/index.js diff --git a/quickstart/javascript/node/package-lock.json b/quickstart/javascript/node/from-file/package-lock.json similarity index 79% rename from quickstart/javascript/node/package-lock.json rename to quickstart/javascript/node/from-file/package-lock.json index cb48e6f73..2a8d5677f 100644 --- a/quickstart/javascript/node/package-lock.json +++ b/quickstart/javascript/node/from-file/package-lock.json @@ -13,19 +13,20 @@ } }, "asn1.js": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.2.0.tgz", - "integrity": "sha512-Q7hnYGGNYbcmGrCPulXfkEw7oW7qjWeM4ZTALmgpuIcZLxyqqKYWxCZg2UBm8bklrnB4m2mGyJPWfoktdORD8A==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.3.0.tgz", + "integrity": "sha512-WHnQJFcOrIWT1RLOkFFBQkFVvyt9BPOOrH+Dp152Zk4R993rSzXUGPmkybIcUFhHE2d/iHH+nCaOWVCDbO8fgA==", "requires": { "bn.js": "^4.0.0", "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0" + "minimalistic-assert": "^1.0.0", + "safer-buffer": "^2.1.0" } }, "asn1.js-rfc2560": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/asn1.js-rfc2560/-/asn1.js-rfc2560-5.0.0.tgz", - "integrity": "sha512-I3bOj/If4sMFmV6Oru93DIDvdENVKVretVpVIp5fe3MACM2HasbnMvTW1fdzbUiHcmMYI+5WfBiboHkIa4j4ew==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/asn1.js-rfc2560/-/asn1.js-rfc2560-5.0.1.tgz", + "integrity": "sha512-1PrVg6kuBziDN3PGFmRk3QrjpKvP9h/Hv5yMrFZvC1kpzP6dQRzf5BpKstANqHBkaOUmTpakJWhicTATOA/SbA==", "requires": { "asn1.js-rfc5280": "^3.0.0" } @@ -38,11 +39,6 @@ "asn1.js": "^5.0.0" } }, - "async-limiter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", - "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" - }, "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", @@ -96,9 +92,9 @@ }, "dependencies": { "https-proxy-agent": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.3.tgz", - "integrity": "sha512-Ytgnz23gm2DVftnzqRRz2dOXZbGd2uiajSw/95bPp6v53zPRspQjLm/AfBgqbJ2qfeRXWIOMVLpp86+/5yX39Q==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz", + "integrity": "sha512-+ML2Rbh6DAuee7d07tYGEKOEi2voWPUGan+ExdPbPW6Z3svq+JCqr0v8WmKPOkz1vOVykPCBSuobe7G8GJUtVg==", "requires": { "agent-base": "^4.3.0", "debug": "^3.1.0" @@ -116,18 +112,20 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "simple-lru-cache": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/simple-lru-cache/-/simple-lru-cache-0.0.2.tgz", "integrity": "sha1-1ZzDoZPBpdAyD4Tucy9uRxPlEd0=" }, "ws": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", - "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", - "requires": { - "async-limiter": "~1.0.0" - } + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", + "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==" } } } diff --git a/quickstart/javascript/node/package.json b/quickstart/javascript/node/from-file/package.json similarity index 100% rename from quickstart/javascript/node/package.json rename to quickstart/javascript/node/from-file/package.json diff --git a/quickstart/javascript/node/text-to-speech/README.md b/quickstart/javascript/node/text-to-speech/README.md new file mode 100644 index 000000000..60e94001b --- /dev/null +++ b/quickstart/javascript/node/text-to-speech/README.md @@ -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) diff --git a/quickstart/javascript/node/text-to-speech/index.js b/quickstart/javascript/node/text-to-speech/index.js new file mode 100644 index 000000000..ba60ee7d3 --- /dev/null +++ b/quickstart/javascript/node/text-to-speech/index.js @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +(function() { + // + "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); + }); + // + +}()); + \ No newline at end of file diff --git a/quickstart/javascript/node/text-to-speech/package-lock.json b/quickstart/javascript/node/text-to-speech/package-lock.json new file mode 100644 index 000000000..af6585600 --- /dev/null +++ b/quickstart/javascript/node/text-to-speech/package-lock.json @@ -0,0 +1,136 @@ +{ + "name": "speech-sdk-quickstart-node-tts", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "agent-base": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.3.0.tgz", + "integrity": "sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==", + "requires": { + "es6-promisify": "^5.0.0" + } + }, + "asn1.js": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.3.0.tgz", + "integrity": "sha512-WHnQJFcOrIWT1RLOkFFBQkFVvyt9BPOOrH+Dp152Zk4R993rSzXUGPmkybIcUFhHE2d/iHH+nCaOWVCDbO8fgA==", + "requires": { + "bn.js": "^4.0.0", + "inherits": "^2.0.1", + "minimalistic-assert": "^1.0.0", + "safer-buffer": "^2.1.0" + } + }, + "asn1.js-rfc2560": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/asn1.js-rfc2560/-/asn1.js-rfc2560-5.0.1.tgz", + "integrity": "sha512-1PrVg6kuBziDN3PGFmRk3QrjpKvP9h/Hv5yMrFZvC1kpzP6dQRzf5BpKstANqHBkaOUmTpakJWhicTATOA/SbA==", + "requires": { + "asn1.js-rfc5280": "^3.0.0" + } + }, + "asn1.js-rfc5280": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/asn1.js-rfc5280/-/asn1.js-rfc5280-3.0.0.tgz", + "integrity": "sha512-Y2LZPOWeZ6qehv698ZgOGGCZXBQShObWnGthTrIFlIQjuV1gg2B8QOhWFRExq/MR1VnPpIIe7P9vX2vElxv+Pg==", + "requires": { + "asn1.js": "^5.0.0" + } + }, + "bn.js": { + "version": "4.11.8", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", + "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" + }, + "debug": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", + "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "requires": { + "ms": "^2.1.1" + } + }, + "es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==" + }, + "es6-promisify": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz", + "integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=", + "requires": { + "es6-promise": "^4.0.3" + } + }, + "https-proxy-agent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-3.0.0.tgz", + "integrity": "sha512-y4jAxNEihqvBI5F3SaO2rtsjIOnnNA8sEbuiP+UhJZJHeM2NRm6c09ax2tgqme+SgUUvjao2fJXF4h3D6Cb2HQ==", + "requires": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "microsoft-cognitiveservices-speech-sdk": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.11.0.tgz", + "integrity": "sha512-03nPTggWCjkvVvJ6Y795UUKkFhdVn32yYqIpI/vEvAQAssffbcP5syU8JfUzN9TF4UfYvUFKlnyNgGj7y1DyAw==", + "requires": { + "asn1.js-rfc2560": "^5.0.0", + "asn1.js-rfc5280": "^3.0.0", + "https-proxy-agent": "^3.0.1", + "simple-lru-cache": "0.0.2", + "ws": "^7.2.0" + }, + "dependencies": { + "https-proxy-agent": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz", + "integrity": "sha512-+ML2Rbh6DAuee7d07tYGEKOEi2voWPUGan+ExdPbPW6Z3svq+JCqr0v8WmKPOkz1vOVykPCBSuobe7G8GJUtVg==", + "requires": { + "agent-base": "^4.3.0", + "debug": "^3.1.0" + } + } + } + }, + "minimalistic-assert": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "simple-lru-cache": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/simple-lru-cache/-/simple-lru-cache-0.0.2.tgz", + "integrity": "sha1-1ZzDoZPBpdAyD4Tucy9uRxPlEd0=" + }, + "ws": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", + "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==" + } + } +} diff --git a/quickstart/javascript/node/text-to-speech/package.json b/quickstart/javascript/node/text-to-speech/package.json new file mode 100644 index 000000000..95985d536 --- /dev/null +++ b/quickstart/javascript/node/text-to-speech/package.json @@ -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" + } +} diff --git a/samples/js/node/README.md b/samples/js/node/README.md index 1cb51a1b9..e77f98b6c 100644 --- a/samples/js/node/README.md +++ b/samples/js/node/README.md @@ -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 @@ -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 diff --git a/samples/js/node/index.js b/samples/js/node/index.js index 85eace05b..e8f395410 100644 --- a/samples/js/node/index.js +++ b/samples/js/node/index.js @@ -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. @@ -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: @@ -51,7 +57,7 @@ } } else { - console.log("usage: index.js [speech|intent|translate] {filename}"); + console.log("usage: index.js [speech|intent|translate|synthesis] {filename}"); } }()); \ No newline at end of file diff --git a/samples/js/node/package-lock.json b/samples/js/node/package-lock.json index 112853e95..1d9e5f47e 100644 --- a/samples/js/node/package-lock.json +++ b/samples/js/node/package-lock.json @@ -13,19 +13,20 @@ } }, "asn1.js": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.2.0.tgz", - "integrity": "sha512-Q7hnYGGNYbcmGrCPulXfkEw7oW7qjWeM4ZTALmgpuIcZLxyqqKYWxCZg2UBm8bklrnB4m2mGyJPWfoktdORD8A==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.3.0.tgz", + "integrity": "sha512-WHnQJFcOrIWT1RLOkFFBQkFVvyt9BPOOrH+Dp152Zk4R993rSzXUGPmkybIcUFhHE2d/iHH+nCaOWVCDbO8fgA==", "requires": { "bn.js": "^4.0.0", "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0" + "minimalistic-assert": "^1.0.0", + "safer-buffer": "^2.1.0" } }, "asn1.js-rfc2560": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/asn1.js-rfc2560/-/asn1.js-rfc2560-5.0.0.tgz", - "integrity": "sha512-I3bOj/If4sMFmV6Oru93DIDvdENVKVretVpVIp5fe3MACM2HasbnMvTW1fdzbUiHcmMYI+5WfBiboHkIa4j4ew==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/asn1.js-rfc2560/-/asn1.js-rfc2560-5.0.1.tgz", + "integrity": "sha512-1PrVg6kuBziDN3PGFmRk3QrjpKvP9h/Hv5yMrFZvC1kpzP6dQRzf5BpKstANqHBkaOUmTpakJWhicTATOA/SbA==", "requires": { "asn1.js-rfc5280": "^3.0.0" } @@ -38,11 +39,6 @@ "asn1.js": "^5.0.0" } }, - "async-limiter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz", - "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==" - }, "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", @@ -96,9 +92,9 @@ }, "dependencies": { "https-proxy-agent": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-2.2.3.tgz", - "integrity": "sha512-Ytgnz23gm2DVftnzqRRz2dOXZbGd2uiajSw/95bPp6v53zPRspQjLm/AfBgqbJ2qfeRXWIOMVLpp86+/5yX39Q==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz", + "integrity": "sha512-+ML2Rbh6DAuee7d07tYGEKOEi2voWPUGan+ExdPbPW6Z3svq+JCqr0v8WmKPOkz1vOVykPCBSuobe7G8GJUtVg==", "requires": { "agent-base": "^4.3.0", "debug": "^3.1.0" @@ -116,18 +112,25 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "simple-lru-cache": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/simple-lru-cache/-/simple-lru-cache-0.0.2.tgz", "integrity": "sha1-1ZzDoZPBpdAyD4Tucy9uRxPlEd0=" }, "ws": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", - "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", - "requires": { - "async-limiter": "~1.0.0" - } + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz", + "integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ==" } } } diff --git a/samples/js/node/package.json b/samples/js/node/package.json index 859c2ab9d..8994a7628 100644 --- a/samples/js/node/package.json +++ b/samples/js/node/package.json @@ -11,6 +11,7 @@ "license": "MIT", "dependencies": { "https-proxy-agent": "^3.0.0", - "microsoft-cognitiveservices-speech-sdk": "^1.11.0" + "microsoft-cognitiveservices-speech-sdk": "^1.11.0", + "readline": "^1.3.0" } } diff --git a/samples/js/node/synthesis.js b/samples/js/node/synthesis.js new file mode 100644 index 000000000..b22c0ab65 --- /dev/null +++ b/samples/js/node/synthesis.js @@ -0,0 +1,86 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +// pull in the required packages. +var sdk = require("microsoft-cognitiveservices-speech-sdk"); +var readline = require("readline"); + +(function() { +"use strict"; + +module.exports = { + main: function(settings, filename) { + + // now create the audio-config pointing to the output file. + // You can also use audio output stream to initialize the audio config, see the docs for details. + var audioConfig = sdk.AudioConfig.fromAudioFileOutput(filename); + var speechConfig = sdk.SpeechConfig.fromSubscription(settings.subscriptionKey, settings.serviceRegion); + + // setting the synthesis language, voice name, and output audio format. + // see https://aka.ms/speech/tts-languages for available languages and voices + speechConfig.speechSynthesisLanguage = settings.language; + speechConfig.speechSynthesisVoiceName = "en-US-JessaRUS"; + speechConfig.speechSynthesisOutputFormat = sdk.SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3; + + var rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + // create the speech synthesizer. + var synthesizer = new sdk.SpeechSynthesizer(speechConfig, audioConfig); + + // Before beginning speech synthesis, setup the callbacks to be invoked when an event occurs. + + // The event synthesizing signals that a synthesized audio chunk is received. + // You will receive one or more synthesizing events as a speech phrase is synthesized. + // You can use this callback to streaming receive the synthesized audio. + synthesizer.synthesizing = function (s, e) { + var str = "(synthesizing) Reason: " + sdk.ResultReason[e.result.reason] + " Audio chunk length: " + e.result.audioData.byteLength; + console.log(str); + }; + + // The event synthesis completed signals that the synthesis is completed. + synthesizer.synthesisCompleted = function (s, e) { + console.log("(synthesized) Reason: " + sdk.ResultReason[e.result.reason] + " Audio length: " + e.result.audioData.byteLength); + }; + + // The synthesis started event signals that the synthesis is started. + synthesizer.synthesisStarted = function (s, e) { + console.log("(synthesis started)"); + }; + + // The event signals that the service has stopped processing speech. + // This can happen when an error is encountered. + synthesizer.SynthesisCanceled = function (s, e) { + var cancellationDetails = sdk.CancellationDetails.fromResult(e.result); + var str = "(cancel) Reason: " + sdk.CancellationReason[cancellationDetails.reason]; + if (cancellationDetails.reason === sdk.CancellationReason.Error) { + str += ": " + e.result.errorDetails; + } + console.log(str); + }; + + // This event signals that word boundary is received. This indicates the audio boundary of each word. + // The unit of e.audioOffset is tick (1 tick = 100 nanoseconds), divide by 10,000 to convert to milliseconds. + synthesizer.wordBoundary = function (s, e) { + console.log("(WordBoundary), Text: " + e.text + ", Audio offset: " + e.audioOffset / 10000 + "ms."); + }; + + 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) { + synthesizer.close(); + synthesizer = undefined; + }, + function (err) { + console.trace("err - " + err); + synthesizer.close(); + synthesizer = undefined; + }) + }); + } +} +}());