1.1.7 • Published 8 years ago

cognitive-speech-client v1.1.7

Weekly downloads
6
License
MIT
Repository
github
Last release
8 years ago

Installation

npm install --save cognitive-speech-client

Usage

TypeScript

import { SpeechAuthClient, SpeechClient } from 'cognitive-speech-client';

// Use with Bing Speech endpoint
const client = new SpeechClient(new SpeechAuthClient("key"));

client.recognize(audioBuffer, (err: Error, speech: SpeechResult) => {
  if (err) throw err;
  console.log(speech.header.name);
});
// use with custom speech recognizer (CRIS) endpoint
const auth = new SpeechAuthClient("key", "region"); // e.g. westus
const client = new SpeechClient(auth, "crisEndpoint");
// auto-renew the authentication token
const auth = new SpeechAuthClient("key", "region", true);

JavaScript

const csc = require('cognitive-speech-client');

const client = new csc.SpeechClient(new csc.SpeechAuthClient("key"));
client.recognize(audioBuffer, (err, speech) => {
  if (err) throw err;
  console.log(speech.header.name);
});

Test Suite

Use MockSpeechService to mock a response for any code that relies on SpeechClient without making an actual API call.

MockSpeechService intercepts any call to the speech recognizer and responds with a fake status and result.

AuthClient caches its authentication token, so take that into account when mocking multiple responses on the same client.

import { SpeechAuthClient, SpeechClient, MockSpeechService } from 'cognitive-speech-client';

// Use with Bing Speech endpoint
new MockSpeechService()
  .auth(200, 'fake key')
  .recognize(200, {header:{name:'testable result'}});

const client = new SpeechClient(new SpeechAuthClient('fake key'));

client.recognize(new Buffer(0), (err: Error, speech: SpeechResult) => {
  if (err) throw err;
  expect(speech.header.name).toBe('testable result');
});
// use with custom speech recognizer (CRIS) endpoint
new MockSpeechService('customEndpoint', 'region')
  .auth(200, 'fake key')
  .recognize(200, {header:{name:'testable result'}});

const auth = new SpeechAuthClient("key", "region"); // e.g. westus
const client = new SpeechClient(auth, "crisEndpoint");
1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago