Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down