Updataes?
This commit is contained in:
10
src/asr.ts
10
src/asr.ts
@@ -82,12 +82,12 @@ function combineSpeakerTranscript(chunks: any[], speakers: any[]): string {
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
parentPort?.on('message', async ({ path, model, speaker, torchHome }) => {
|
||||
parentPort?.on('message', async ({ file, speaker, model, modelDir }) => {
|
||||
try {
|
||||
if(!whisperPipeline) whisperPipeline = await pipeline('automatic-speech-recognition', `Xenova/${model}`, {cache_dir: torchHome, quantized: true});
|
||||
if(!whisperPipeline) whisperPipeline = await pipeline('automatic-speech-recognition', `Xenova/${model}`, {cache_dir: modelDir, quantized: true});
|
||||
|
||||
// Prepare audio file (convert to mono channel wave)
|
||||
const wav = new wavefile.WaveFile(fs.readFileSync(path));
|
||||
const wav = new wavefile.WaveFile(fs.readFileSync(file));
|
||||
wav.toBitDepth('32f');
|
||||
wav.toSampleRate(16000);
|
||||
const samples = wav.getSamples();
|
||||
@@ -111,11 +111,11 @@ parentPort?.on('message', async ({ path, model, speaker, torchHome }) => {
|
||||
// Speaker Diarization
|
||||
const hasDiarization = await canDiarization();
|
||||
if(!hasDiarization) {
|
||||
parentPort?.postMessage({ text: transcriptResult.text?.trim() || null, warning: 'Speaker diarization unavailable' });
|
||||
parentPort?.postMessage({ text: transcriptResult.text?.trim() || null, error: 'Speaker diarization unavailable' });
|
||||
return;
|
||||
}
|
||||
|
||||
const speakers = await runDiarization(path, torchHome);
|
||||
const speakers = await runDiarization(file, modelDir);
|
||||
const combined = combineSpeakerTranscript(transcriptResult.chunks || [], speakers);
|
||||
parentPort?.postMessage({ text: combined });
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user