Skip to content

Commit

Permalink
Merge pull request #188 from monte-hayward/dev
Browse files Browse the repository at this point in the history
support for keywords, keywords_threshold, and word_alternatives_thres…
  • Loading branch information
germanattanasio committed Dec 22, 2015
2 parents 5a414a2 + e0dca8d commit 73245dd
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
6 changes: 4 additions & 2 deletions services/speech_to_text/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var util = require('util');
var WebSocketClient = require('websocket').client;
var pkg = require('../../package.json');

var PARAMS_ALLOWED = ['continuous', 'max_alternatives', 'timestamps', 'word_confidence', 'inactivity_timeout',
'model', 'content-type', 'interim_results', 'keywords', 'keywords_threshold', 'word_alternatives_threshold' ];

function formatChunk(chunk) {
// Convert the string into an array
var result = chunk;
Expand Down Expand Up @@ -394,8 +397,7 @@ function RecognizeStream(options){
'content-type': 'audio/wav', // todo: try to determine content-type from the file extension if available
'continuous': false,
'interim_results': true
}, pick(options, ['continuous', 'max_alternatives', 'timestamps',
'word_confidence', 'inactivity_timeout', 'content-type', 'interim_results']));
}, pick(options, [PARAMS_ALLOWED]));

var closingMessage = {action: 'stop'};

Expand Down
71 changes: 70 additions & 1 deletion test/test.speech_to_text.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('speech_to_text', function() {
session_id: 'foo',
new_session_uri: '#',
recognize: '#',
observe_result: '#',
observe_result: '#'
},
new_session_with_cookie = extend({}, new_session, {cookie_session: 'foobar'});

Expand Down Expand Up @@ -226,6 +226,75 @@ describe('speech_to_text', function() {
});
});

describe('recognizeStream()', function() {
var path = '/v1/sessions/foo/recognize',
payload = {
session_id: 'foo',
cookie_session: 'foobar',
content_type: 'audio/l16; rate=41100'
},
service_response = {
result: [{
alternative: [{
transcript: 'one two three'
}],
'final': true
}],
result_index: 0
};

var options = {
content_type: 'audio/l16;rate=41100',
"continuous": true,
"timestamps":true,
"inactivity_timeout": -1,
"max_alternatives": 1,
"interim_results": false,
"keywords": ['one', 'Three'],
"keywords_threshold": 0.9,
"word_alternatives_threshold": 0.25
};
var recognizeStream = speech_to_text.createRecognizeStream(options);
var DEBUG = fs.createReadStream(__dirname + '/resources/audio.wav').pipe(recognizeStream);
recognizeStream.setEncoding('utf8');

it('should have expected _events', function(done) {
assert.equal(true, recognizeStream.hasOwnProperty('_events'));
assert.equal(true, recognizeStream._events.hasOwnProperty('connect'));
assert.equal(true, recognizeStream._events.hasOwnProperty('end'));
assert.equal(true, recognizeStream._events.hasOwnProperty('results'));
assert.equal(true, recognizeStream._events.hasOwnProperty('error'));
assert.equal(true, recognizeStream._events.hasOwnProperty('finish'));
assert.equal(true, recognizeStream._events.hasOwnProperty('listening'));
done();
});

recognizeStream.on('connect', function(socket){
it('should have a socket connection with a correct config', function(done){
assert.notStrictEqual(socket, socket.config, socket.config.fragmentOutgoingMessages);
assert.notStrictEqual(socket, socket.config, socket.config.fragmentOutgoingMessages);
done();
});
});

recognizeStream.on('error', function(err){
it('should throw ECONNRESET with bad credentials', function(done){
assert.equal(err.code, 'ECONNRESET');
assert.equal(err.errno, 'ECONNRESET');
done();
});
});

recognizeStream.on('results', function(obj){
console.log(JSON.stringify(obj));
it('should generate a valid response', function(done) {
assert.equal(obj, service_response);
done();
});
});
});


describe('recognizeLive()', function() {
var path = '/v1/sessions/foo/recognize',
payload = {
Expand Down

0 comments on commit 73245dd

Please sign in to comment.