SYSTRAN / faster-whisper

Faster Whisper transcription with CTranslate2
MIT License
12.51k stars 1.05k forks source link

Separate language detection into a standalone method & Convert test framework into unittest from pytest. #906

Closed zh-plus closed 4 months ago

zh-plus commented 4 months ago

Separate language detection into a standalone method

After the latest update (v1.0.3) to Silero-Vad V5, I noticed that the VAD threshold value is highly dependent on the language. For English, the default threshold=0.5 works well. However, for Asian languages like Chinese and Japanese, a threshold<0.2 should be set; otherwise, VAD may filter out 90% of the audio content.

Thus, I plan to add language detection before transcription, such as:

whisper_model = WhisperModel(model_name, device, compute_type=compute_type)

# Set VAD threshold here according to the detected language
language = ...
vad_options = get_vad_options(language)

seg_gen, info = whisper_model.transcribe(str(audio_path), language=language,
                                         vad_filter=True, vad_parameters=vad_options)

I found that faster-whisper can already detect languages during the whisper_model.transcribe process. However, this feature is embedded and not directly accessible to users. So, I submitted a PR to separate it from the transcribe method, which also reduces its complexity (from 176 to 120 lines of code).

Now we can perform the language detection before transcription by:

whisper_model = WhisperModel(model_name, device, compute_type=compute_type)
lang, lang_prob, all_lang_probs, _ = whisper_model.detect_language(AUDIO_PATH)

Convert test framework into unittest from pytest

While adding related tests, I noticed we are using the pytest framework, which introduces extra dependencies. Thus, I converted all test suites to unittest and updated the dependency requirements.