File size: 800 Bytes
5e1b738
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { pipeline } from "@huggingface/transformers";
import { read_audio } from "./utils.js";

// Load model
const transcriber = await pipeline(
  "automatic-speech-recognition",
  "onnx-community/whisper-tiny.en",
  { dtype: { encoder_model: "fp32", decoder_model_merged: "q4" } },
);

// Load audio data
const audio = await read_audio(
  "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav",
  transcriber.processor.feature_extractor.config.sampling_rate,
);

// Run model w/ default settings
console.time("Execution time");
const output = await transcriber(audio);
console.timeEnd("Execution time");
console.log(output);
// { text: ' And so my fellow Americans ask not what your country can do for you, ask what you can do for your country.' }