/node-google-speech-api

Google speech api wrapper for node

Primary LanguageJavaScriptMIT LicenseMIT

Google Speech API

Build Status

Google Speech API wrapper for node. It requires FFmpeg compiled with flac support in order to work.

1.0.0 Update

Switched from SoX to FFmpeg. Make sure you have at least version 0.9 of ffmpeg.

0.5 Update

The google speech api now requires an API Key. You'll have to create an app in the Google Developers Console and enable the speech api.

To enable the speech api in the developer console you must join the chromium dev-list in google groups. See these comments for more details.

The response format has also changed. Instead of returning utterances, google now returns alternatives with a transcript. See the example below.

Usage

var speech = require('google-speech-api');

var opts = {
  file: 'speech.mp3',
  key: '<Google API Key>'
};

speech(opts, function (err, results) {
  console.log(results);
  // [{result: [{alternative: [{transcript: '...'}]}]}]
});

Piping

You can pipe data:

var request = require('superagent');
var speech = require('google-speech-api');

// must specify the filetype when piping
var opts = {filetype: 'mp3'};

request
  .get('http://../../file.mp3')
  .pipe(speech(opts, function (err, results) {
    // handle the results
  }));

Options

You can specify several options:

  • clipSize — The audio duration of files sent to google (in seconds.) Larger files will be broken into pieces. (defaults to 15)
  • file — The audio file. May be a string path or a Buffer object. (required)
  • key — Your google API key. (required)
  • client — The name of the client you are connecting with. (defaults to "chromium")
  • filetype — Specify the file type. Required when piping or if the file is a buffer object.
  • lang — The spoken language in the file. (defaults to "en-US")
  • maxRequests — The maximum number of clips to send to google at a time. (defaults to 4)
  • maxResults — The maximum number of hypotheses returned by google. (defaults to 1)
  • pfilter — Filter profanity by replacing flagged words with pound symbols. Set 0 to unfilter. (defaults to 1)
  • sampleRate — The sample rate of the audio sent to google. (defaults to 16000)
  • xjerr — Return errors as part of the JSON response if set to 1, otherwise returns errors as HTTP error codes. (defaults to 1)