m-bain / whisperX

WhisperX: Automatic Speech Recognition with Word-level Timestamps (& Diarization)
BSD 2-Clause "Simplified" License
12.61k stars 1.34k forks source link

How to enable diarization in python code (not terminal)? #858

Closed imc-db closed 3 months ago

imc-db commented 3 months ago

I don't find any possibility to enable diarization from python code? Any help would be really appreciated.

model = whisper.load_model(model_whisper, device=device, diarize=True) # ---> TypeError: load_model() got an unexpected keyword argument 'diarize'

model = whisper.load_model(model_whisper, device=device)

Same happens if I add this parameter to transcribe(...)

result = model.transcribe(audio_file)

bl4ckwind commented 3 months ago
diarize_model = whisperx.DiarizationPipeline(
    use_auth_token="<YOUR_HF_TOKEN>", device=device
)
diarize_segments = diarize_model(whisperx.load_audio(audio_file_path), num_speakers=2)
result: DataFrame = whisperx.assign_word_speakers(diarize_segments, result)
Scronkfink commented 3 months ago

You can also make it into a shell command and run that instead.