palmerabollo / bingspeech-api-client

Microsoft Bing Speech API client in node.js
Other
32 stars 17 forks source link
bing-speech speech-to-text stt text-to-speech tts

bingspeech-api-client

A Microsoft Bing Speech API client written in node.js.

Official documentation for Bing Speech API service.

To work with Bing Speech API, you must have a subscription key. If you don't have a subscription key already, get one here: Subscriptions.

Usage

Install bingspeech-api-client in your node project with npm.

npm install --save bingspeech-api-client

See example below on how to require and use for Speech to text (STT) and text to speech (TTS).

Examples

Following example code is assuming you are using typescript. If you are, skip this section and go straight to the examples. But if you are using node ES6 and want to use the example code read on.

At present node does not support import. As mentioned on MDN

Note: This feature[import] is only beginning to be implemented in browsers natively at this time. It is implemented in many transpilers, such as the Traceur Compiler, Babel, Rollup or Webpack.

To get the example code working change the first line to:

const { BingSpeechClient, VoiceRecognitionResponse } = require('bingspeech-api-client');

STT usage example (recognize)

import { BingSpeechClient, VoiceRecognitionResponse } from 'bingspeech-api-client';

let audioStream = fs.createReadStream(myFileName); // create audio stream from any source

// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = 'your_private_subscription_key';

let client = new BingSpeechClient(subscriptionKey);
client.recognizeStream(audioStream).then(response => console.log(response.results[0].name));

TTS usage example (synthesize)

import { BingSpeechClient, VoiceVoiceSynthesisResponse } from 'bingspeech-api-client';

// Bing Speech Key (https://www.microsoft.com/cognitive-services/en-us/subscriptions)
let subscriptionKey = 'your_private_subscription_key';

let client = new BingSpeechClient(subscriptionKey);
client.synthesizeStream('I have a dream').then(audioStream => /* ... */);