This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

witspeech

0.0.1 • Public • Published

Wit speech

Makes network request to Wit.ai's speech API. For more information about the API see the official documentation.

Installation

npm install --save witspeech

Usage

Constructor

// Import module.
const WitSpeech = require('witspeech');
// Create an instance.
const witSpeech = new WitSpeech('WIT_TOKEN', '20171207');

Replace WIT_TOKEN with your token retrieved from the wit.ai website.

Methods

// The type of content that you will stream.
let contentType = 'audio/wav';
// Additional and optional web request parameters.
let queryParameters = {};
// Callback function with the response.
let callback = function(error, response) {
  if (error) {
    console.error('ERROR', error);
    return;
  }
  console.log(JSON.parse(response));
};
 
// Retrieves the web request to pipe information to.
witSpeech.request(
  contentType,
  queryParameters,
  callback
);

To see what content types you can send over see the official documentation.

Example

From file

// Import node module.
const fs = require('fs');
 
// Initialize module, see constructor section for more information.
const WitSpeech = require('witspeech');
const witSpeech = new WitSpeech('WIT_TOKEN', '20171207');
 
// Create request, see methods section for more information.
let request = witSpeech.request('audio/wav', {}, function(error, response) {
  if (error) {
    console.error('ERROR', error);
    return;
  }
  console.log(JSON.parse(response));
});
 
// Create read file stream.
let stream = fs.createReadStream('audio.wav');
// Pipe the stream to the request.
stream.pipe(request);

From microphone

// Initialize module, see constructor section for more information.
const WitSpeech = require('witspeech');
const witSpeech = new WitSpeech('WIT_TOKEN', '20171207');
 
// Import audio recorder
const AudioRecorder = require('node-audiorecorder');
const audioRecorder = new AudioRecorder();
 
// Create request, see methods section for more information.
let request = witSpeech.request('audio/wav', {}, function(error, response) {
  if (error) {
    console.error('ERROR', error);
    return;
  }
  console.log(JSON.parse(response));
});
 
// Start audio recorder.
audioRecorder.start();
// Get microphone stream.
let stream = audioRecorder.stream();
// Pipe the stream to the request.
stream.pipe(request);

For the audio recorder see the package or repository for it.

For another example see the Electron-VoiceInterfacePrototype's input.js.

Package Sidebar

Install

npm i witspeech

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • redkenrok