Merge pull request #3011 from mozilla/pr3010

PR #3010 - Fix Stream.intermediateDecodeWithMetadata + tests
This commit is contained in:
Reuben Morais 2020-05-25 12:01:29 +02:00 committed by GitHub
commit 0ed7d301e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -132,6 +132,12 @@ if (!args['stream']) {
let stream = model.createStream();
conversionStream.on('data', (chunk: Buffer) => {
stream.feedAudioContent(chunk);
if (args['extended']) {
let metadata = stream.intermediateDecodeWithMetadata();
console.error('intermediate: ' + candidateTranscriptToString(metadata.transcripts[0]));
} else {
console.error('intermediate: ' + stream.intermediateDecode());
}
});
conversionStream.on('end', () => {
if (args['extended']) {

View File

@ -90,7 +90,7 @@ setScorerAlphaBeta(aLMAlpha: number, aLMBeta: number): number;
*
* @return The STT result. Returns undefined on error.
*/
stt(aBuffer: object): string;
stt(aBuffer: Buffer): string;
/**
* Use the DeepSpeech model to perform Speech-To-Text and output metadata
@ -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: Buffer, 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.
@ -134,7 +134,7 @@ feedAudioContent(aBuffer: Buffer): void;
*
* @return The STT intermediate result.
*/
intermediateDecode(aSctx: Stream): string;
intermediateDecode(): string;
/**
* Compute the intermediate decoding of an ongoing streaming inference, return results including metadata.

View File

@ -184,7 +184,7 @@ Stream.prototype.intermediateDecode = function() {
*/
Stream.prototype.intermediateDecodeWithMetadata = function(aNumResults) {
aNumResults = aNumResults || 1;
return binding.IntermediateDecode(this._impl, aNumResults);
return binding.IntermediateDecodeWithMetadata(this._impl, aNumResults);
}
/**