Fix ASR
This commit is contained in:
12
src/audio.ts
12
src/audio.ts
@@ -1,6 +1,8 @@
|
||||
import {spawn} from 'node:child_process';
|
||||
import {pipeline, read_audio} from '@xenova/transformers';
|
||||
import {pipeline} from '@xenova/transformers';
|
||||
import * as fs from 'node:fs';
|
||||
import {AbortablePromise, Ai} from './ai.ts';
|
||||
import * as wavefile from 'wavefile';
|
||||
|
||||
export class Audio {
|
||||
private whisperPipeline: any;
|
||||
@@ -96,8 +98,12 @@ print(json.dumps(segments))
|
||||
|
||||
// Transcript
|
||||
if(aborted) return resolve(null);
|
||||
const audio = await read_audio(path, 16000);
|
||||
const transcriptResult = await this.whisperPipeline(audio, {return_timestamps: speaker ? 'word' : false, chunk_length_s: 30,});
|
||||
const audioData = fs.readFileSync(path);
|
||||
const wav = new wavefile.WaveFile(audioData);
|
||||
wav.toBitDepth('32f');
|
||||
wav.toSampleRate(16000);
|
||||
const buffer = wav.getSamples();
|
||||
const transcriptResult = await this.whisperPipeline(buffer, {return_timestamps: speaker ? 'word' : false, chunk_length_s: 30,});
|
||||
if(!speaker) return resolve(transcriptResult.text?.trim() || null);
|
||||
|
||||
// Speaker Diarization
|
||||
|
||||
Reference in New Issue
Block a user