From 41d990e5383b36ba9a2ce4b867214b5f81c06110 Mon Sep 17 00:00:00 2001 From: Matt McCartney Date: Tue, 5 May 2020 14:32:07 -0700 Subject: [PATCH 1/4] fix(js): declare FinishStreamWithMetadata result object - as demanded by strict mode close #2979 --- native_client/javascript/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native_client/javascript/index.js b/native_client/javascript/index.js index 7d742aad..e349b69d 100644 --- a/native_client/javascript/index.js +++ b/native_client/javascript/index.js @@ -211,7 +211,7 @@ Stream.prototype.finishStream = function() { */ Stream.prototype.finishStreamWithMetadata = function(aNumResults) { aNumResults = aNumResults || 1; - result = binding.FinishStreamWithMetadata(this._impl, aNumResults); + let result = binding.FinishStreamWithMetadata(this._impl, aNumResults); this._impl = null; return result; } From e6e3cc539b8745ea39040c40e0ba97e6b198accd Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Wed, 6 May 2020 12:03:14 +0200 Subject: [PATCH 2/4] Mark aNumResults parameters in *withMetadata methods as optional --- native_client/javascript/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/native_client/javascript/index.d.ts b/native_client/javascript/index.d.ts index b22141ca..dfe365cd 100644 --- a/native_client/javascript/index.d.ts +++ b/native_client/javascript/index.d.ts @@ -103,7 +103,7 @@ stt(aBuffer: object): string; * @return :js:func:`Metadata` object containing multiple candidate transcripts. Each transcript has per-token metadata including timing information. * The user is responsible for freeing Metadata by calling :js:func:`FreeMetadata`. Returns undefined on error. */ -sttWithMetadata(aBuffer: object, aNumResults: number): Metadata; +sttWithMetadata(aBuffer: object, aNumResults?: number): Metadata; /** * Create a new streaming inference state. One can then call :js:func:`Stream.feedAudioContent` and :js:func:`Stream.finishStream` on the returned stream object. @@ -143,7 +143,7 @@ intermediateDecode(aSctx: Stream): string; * * @return :js:func:`Metadata` object containing multiple candidate transcripts. Each transcript has per-token metadata including timing information. The user is responsible for freeing Metadata by calling :js:func:`FreeMetadata`. Returns undefined on error. */ -intermediateDecodeWithMetadata (aNumResults: number): Metadata; +intermediateDecodeWithMetadata (aNumResults?: number): Metadata; /** * Compute the final decoding of an ongoing streaming inference and return the result. Signals the end of an ongoing streaming inference. @@ -163,7 +163,7 @@ finishStream(): string; * * This method will free the stream, it must not be used after this method is called. */ -finishStreamWithMetadata(aNumResults: number): Metadata; +finishStreamWithMetadata(aNumResults?: number): Metadata; } /** From b0e0972b78e4e931aa62c4db842a9373c61fd153 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Wed, 6 May 2020 12:03:50 +0200 Subject: [PATCH 3/4] Fix reference to Stream.finishStreamWithMetadata --- native_client/javascript/index.d.ts | 2 +- native_client/javascript/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/native_client/javascript/index.d.ts b/native_client/javascript/index.d.ts index dfe365cd..339fb36e 100644 --- a/native_client/javascript/index.d.ts +++ b/native_client/javascript/index.d.ts @@ -177,7 +177,7 @@ export function FreeModel(model: Model): void; /** * Free memory allocated for metadata information. * - * @param metadata Object containing metadata as returned by :js:func:`Model.sttWithMetadata` or :js:func:`Model.finishStreamWithMetadata` + * @param metadata Object containing metadata as returned by :js:func:`Model.sttWithMetadata` or :js:func:`Stream.finishStreamWithMetadata` */ export function FreeMetadata(metadata: Metadata): void; diff --git a/native_client/javascript/index.js b/native_client/javascript/index.js index e349b69d..f684f503 100644 --- a/native_client/javascript/index.js +++ b/native_client/javascript/index.js @@ -230,7 +230,7 @@ function FreeModel(model) { /** * Free memory allocated for metadata information. * - * @param {object} metadata Object containing metadata as returned by :js:func:`Model.sttWithMetadata` or :js:func:`Model.finishStreamWithMetadata` + * @param {object} metadata Object containing metadata as returned by :js:func:`Model.sttWithMetadata` or :js:func:`Stream.finishStreamWithMetadata` */ function FreeMetadata(metadata) { return binding.FreeMetadata(metadata); From a02eddec385ab95d8f746ad570a670586e2ad87c Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Wed, 6 May 2020 12:04:17 +0200 Subject: [PATCH 4/4] Add JS test for streaming + metadata --- native_client/javascript/client.ts | 7 ++++++- taskcluster/tc-asserts.sh | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/native_client/javascript/client.ts b/native_client/javascript/client.ts index ecf00a95..d607060e 100644 --- a/native_client/javascript/client.ts +++ b/native_client/javascript/client.ts @@ -134,6 +134,11 @@ if (!args['stream']) { stream.feedAudioContent(chunk); }); conversionStream.on('end', () => { - console.log(stream.finishStream()); + if (args['extended']) { + let metadata = stream.finishStreamWithMetadata(); + console.log(candidateTranscriptToString(metadata.transcripts[0])); + } else { + console.log(stream.finishStream()); + } }); } diff --git a/taskcluster/tc-asserts.sh b/taskcluster/tc-asserts.sh index 62f1e8ff..a56a4c49 100755 --- a/taskcluster/tc-asserts.sh +++ b/taskcluster/tc-asserts.sh @@ -519,6 +519,12 @@ run_js_streaming_inference_tests() status=$? set -e assert_correct_ldc93s1_lm "${phrase_pbmodel_withlm}" "$status" + + set +e + phrase_pbmodel_withlm=$(deepspeech --model ${TASKCLUSTER_TMP_DIR}/${model_name_mmap} --scorer ${TASKCLUSTER_TMP_DIR}/kenlm.scorer --audio ${TASKCLUSTER_TMP_DIR}/${ldc93s1_sample_filename} --stream --extended 2>${TASKCLUSTER_TMP_DIR}/stderr | tail -n 1) + status=$? + set -e + assert_correct_ldc93s1_lm "${phrase_pbmodel_withlm}" "$status" } run_js_streaming_prod_inference_tests() @@ -529,4 +535,11 @@ run_js_streaming_prod_inference_tests() status=$? set -e assert_correct_ldc93s1_prodmodel "${phrase_pbmodel_withlm}" "$status" "${_bitrate}" + + local _bitrate=$1 + set +e + phrase_pbmodel_withlm=$(deepspeech --model ${TASKCLUSTER_TMP_DIR}/${model_name_mmap} --scorer ${TASKCLUSTER_TMP_DIR}/kenlm.scorer --audio ${TASKCLUSTER_TMP_DIR}/${ldc93s1_sample_filename} --stream --extended 2>${TASKCLUSTER_TMP_DIR}/stderr | tail -n 1) + status=$? + set -e + assert_correct_ldc93s1_prodmodel "${phrase_pbmodel_withlm}" "$status" "${_bitrate}" }