Makes network request to Wit.ai's speech API. For more information about the API see the official documentation.
npm install --save witspeech
// Import module.
const WitSpeech = require('witspeech');
// Create an instance.
const witSpeech = new WitSpeech('KEY_CLIENT', '20171207');Replace 'KEY_CLIENT' with your Client Access Token retrieved from the wit.ai website.
// 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.
// Import node module.
const fs = require('fs');
// Initialize module, see constructor section for more information.
const WitSpeech = require('witspeech');
const witSpeech = new WitSpeech('KEY_CLIENT', '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);// Initialize module, see constructor section for more information.
const WitSpeech = require('witspeech');
const witSpeech = new WitSpeech('KEY_CLIENT', '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-VoiceInterfaceBoilerplate's input.js.