Merge pull request #3361 from imrahul361/master

enable hot-words boosting for Javascript
This commit is contained in:
lissyx 2020-10-10 16:00:47 +02:00 committed by GitHub
commit 7ca237d19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View File

@ -31,6 +31,7 @@ parser.addArgument(['--audio'], {required: true, help: 'Path to the audio file t
parser.addArgument(['--version'], {action: VersionAction, nargs: 0, help: 'Print version and exits'});
parser.addArgument(['--extended'], {action: 'storeTrue', help: 'Output string from extended metadata'});
parser.addArgument(['--stream'], {action: 'storeTrue', help: 'Use streaming code path (for tests)'});
parser.addArgument(['--hot_words'], {help: 'Hot-words and their boosts. Word:Boost pairs are comma-separated'});
let args = parser.parseArgs();
function totalTime(hrtimeValue: number[]): string {
@ -71,6 +72,14 @@ if (args['scorer']) {
}
}
if (args['hot_words']) {
console.error('Adding hot-words %s', args['hot_words']);
for (let word_boost of args['hot_words'].split(',')) {
let word = word_boost.split(':');
model.addHotWord(word[0], parseFloat(word[1]));
}
}
const buffer = Fs.readFileSync(args['audio']);
const result = Wav.decode(buffer);

View File

@ -191,7 +191,7 @@ export class Model {
* @throws on error
*/
addHotWord(aWord: string, aBoost: number): void {
const status = binding.addHotWord(this._impl, aWord, aBoost);
const status = binding.AddHotWord(this._impl, aWord, aBoost);
if (status !== 0) {
throw `addHotWord failed: ${binding.ErrorCodeToErrorMessage(status)} (0x${status.toString(16)})`;
}
@ -205,7 +205,7 @@ export class Model {
* @throws on error
*/
eraseHotWord(aWord: string): void {
const status = binding.eraseHotWord(this._impl, aWord);
const status = binding.EraseHotWord(this._impl, aWord);
if (status !== 0) {
throw `eraseHotWord failed: ${binding.ErrorCodeToErrorMessage(status)} (0x${status.toString(16)})`;
}
@ -217,7 +217,7 @@ export class Model {
* @throws on error
*/
clearHotWords(): void {
const status = binding.clearHotWords(this._impl);
const status = binding.ClearHotWords(this._impl);
if (status !== 0) {
throw `clearHotWord failed: ${binding.ErrorCodeToErrorMessage(status)} (0x${status.toString(16)})`;
}

View File

@ -34,3 +34,5 @@ ensure_cuda_usage "$3"
run_all_inference_tests
run_js_streaming_inference_tests
run_hotword_tests

View File

@ -36,3 +36,5 @@ check_runtime_nodejs
run_all_inference_tests
run_js_streaming_inference_tests
run_hotword_tests