File size: 1,047 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
24
25
26
27
28
29
30
31
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_timestamped",
  { 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, { return_timestamps: "word" });
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.',
//   chunks: [
//     { text: ' And', timestamp: [0, 0.76] },
//     { text: ' so', timestamp: [0.76, 1.06] },
//     ...
//     { text: ' country.', timestamp: [10.22, 10.72] },
//   ],
// }