Views
No views yet
npm i @huggingface/transformers1import { pipeline } from '@huggingface/transformers';
2
3// Create speech recognition pipeline
4const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en');
5
6// Transcribe audio from URL
7const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
8const output = await transcriber(url);
9// { text: " And so my fellow Americans ask not what your country can do for you, ask what you can do for your country." }1import { pipeline } from '@huggingface/transformers';
2
3// Create speech recognition pipeline
4const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en');
5
6// Transcribe audio from URL with timestamps
7const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
8const output = await transcriber(url, { return_timestamps: true });
9// {
10// text: " And so my fellow Americans ask not what your country can do for you, ask what you can do for your country."
11// chunks: [
12// { timestamp: [0, 8], text: " And so my fellow Americans ask not what your country can do for you" }
13// { timestamp: [8, 11], text: " ask what you can do for your country." }
14// ]
15// }1import { pipeline } from '@huggingface/transformers';
2
3// Create speech recognition pipeline
4const transcriber = await pipeline('automatic-speech-recognition', 'Xenova/whisper-tiny.en');
5
6// Transcribe audio from URL with word-level timestamps
7const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/jfk.wav';
8const output = await transcriber(url, { return_timestamps: 'word' });
9// {
10// "text": " And so my fellow Americans ask not what your country can do for you ask what you can do for your country.",
11// "chunks": [
12// { "text": " And", "timestamp": [0, 0.78] },
13// { "text": " so", "timestamp": [0.78, 1.06] },
14// { "text": " my", "timestamp": [1.06, 1.46] },
15// ...
16// { "text": " for", "timestamp": [9.72, 9.92] },
17// { "text": " your", "timestamp": [9.92, 10.22] },
18// { "text": " country.", "timestamp": [10.22, 13.5] }
19// ]
20// }onnx).