From 56a9de4278cc9801afc590b45961243dadd80362 Mon Sep 17 00:00:00 2001 From: jeevan6996 Date: Fri, 14 Aug 2026 19:08:20 +0100 Subject: [PATCH] Fix Moonshine ASR tokenizer decoding --- .../pipelines/automatic-speech-recognition.js | 2 +- ..._pipelines_automatic_speech_recognition.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/transformers/src/pipelines/automatic-speech-recognition.js b/packages/transformers/src/pipelines/automatic-speech-recognition.js index 238bb45a4..429303f7c 100644 --- a/packages/transformers/src/pipelines/automatic-speech-recognition.js +++ b/packages/transformers/src/pipelines/automatic-speech-recognition.js @@ -325,7 +325,7 @@ export class AutomaticSpeechRecognitionPipeline const max_new_tokens = Math.floor(aud.length / sampling_rate) * 6; const outputs = await this.model.generate({ max_new_tokens, ...kwargs, ...inputs }); - const text = this.processor.batch_decode(/** @type {Tensor} */ (outputs), { skip_special_tokens: true })[0]; + const text = this.tokenizer.batch_decode(/** @type {Tensor} */ (outputs), { skip_special_tokens: true })[0]; toReturn.push({ text }); } return single ? toReturn[0] : toReturn; diff --git a/packages/transformers/tests/pipelines/test_pipelines_automatic_speech_recognition.js b/packages/transformers/tests/pipelines/test_pipelines_automatic_speech_recognition.js index 33d67ac92..626b9503f 100644 --- a/packages/transformers/tests/pipelines/test_pipelines_automatic_speech_recognition.js +++ b/packages/transformers/tests/pipelines/test_pipelines_automatic_speech_recognition.js @@ -7,6 +7,33 @@ const PIPELINE_ID = "automatic-speech-recognition"; export default () => { describe("Automatic Speech Recognition", () => { + it("uses the pipeline tokenizer to decode Moonshine output", async () => { + const model = { + config: { model_type: "moonshine" }, + generate: async () => ({}), + dispose: async () => {}, + }; + const processor = Object.assign(async () => ({}), { + feature_extractor: { config: { sampling_rate: 16000 } }, + }); + let decodeCalls = 0; + const tokenizer = { + batch_decode: () => { + decodeCalls += 1; + return ["decoded text"]; + }, + }; + const pipe = new AutomaticSpeechRecognitionPipeline({ + task: PIPELINE_ID, + model, + tokenizer, + processor, + }); + + await expect(pipe._call_moonshine(new Float32Array(16000), {})).resolves.toEqual({ text: "decoded text" }); + expect(decodeCalls).toBe(1); + }); + describe("whisper (tiny-random)", () => { const model_id = "Xenova/tiny-random-WhisperForConditionalGeneration"; const SAMPLING_RATE = 16000;