Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for keywords, keywords_threshold, and word_alternatives_thres… #188

Merged
merged 4 commits into from
Dec 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line should be

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