mirror-jetstream/transformersjs/task-whisper.js
Camillo Bruni 8270d839bf Reset main-custom to latest main version
Following a different approach to better keep main-custom up to date
with main by resetting and merging pending upstream PRs on top.

Change-Id: I26c7a2c63b166715d01b50da0bd47aaf99aa3c1a
Reviewed-on: https://chromium-review.googlesource.com/c/external/github.com/WebKit/JetStream/+/6976606
Reviewed-by: Victor Gomes <victorgomes@chromium.org>
2025-09-24 01:18:07 -07:00

28 lines
915 B
JavaScript

// Copyright 2025 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// End-to-end task 2: Speech recognition.
// Based on the example https://huggingface.co/Xenova/whisper-tiny.en
// Convert audio inputs first with `convert-audio.mjs`.
globalThis.initPipeline = async function(pipeline) {
return await pipeline(
'automatic-speech-recognition',
'Xenova/whisper-tiny.en',
// Use quantized model because of smaller weights.
{ dtype: 'q8' }
);
}
globalThis.doTask = async function(pipeline, inputFileBuffer) {
const input = new Float32Array(inputFileBuffer);
const output = await pipeline(input);
return output.text.trim();
}
globalThis.validate = function(output) {
if (output !== 'Ask not what your country can do for you.') {
throw new Error('Wrong output, got: ' + output);
}
}