mirror of
https://github.com/k2-fsa/sherpa-onnx.git
synced 2026-11-10 13:04:05 +08:00
This pull request introduces support for the Cohere Transcribe model across multiple platforms, including Node.js addons, standard Node.js, and WebAssembly. Key changes include adding C++ configuration logic, implementing a setOption method for offline streams to handle language selection, and providing new example scripts for both synchronous and asynchronous transcription.
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
// Copyright (c) 2026 Xiaomi Corporation (authors: Fangjun Kuang)
|
|
//
|
|
const sherpa_onnx = require('sherpa-onnx');
|
|
|
|
function createOfflineRecognizer() {
|
|
const config = {
|
|
modelConfig: {
|
|
cohereTranscribe: {
|
|
encoder:
|
|
'./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/encoder.int8.onnx',
|
|
decoder:
|
|
'./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/decoder.int8.onnx',
|
|
usePunct: 1,
|
|
useItn: 1,
|
|
},
|
|
tokens:
|
|
'./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/tokens.txt',
|
|
}
|
|
};
|
|
|
|
return sherpa_onnx.createOfflineRecognizer(config);
|
|
}
|
|
|
|
const recognizer = createOfflineRecognizer();
|
|
const stream = recognizer.createStream();
|
|
stream.setOption('language', 'en');
|
|
|
|
const waveFilename =
|
|
'./sherpa-onnx-cohere-transcribe-14-lang-int8-2026-04-01/test_wavs/en.wav';
|
|
const wave = sherpa_onnx.readWave(waveFilename);
|
|
stream.acceptWaveform(wave.sampleRate, wave.samples);
|
|
|
|
recognizer.decode(stream);
|
|
const text = recognizer.getResult(stream).text;
|
|
console.log(text);
|
|
|
|
stream.free();
|
|
recognizer.free();
|