Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Faster Whisper #693

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow setting download root cache path
  • Loading branch information
joshuaboniface committed Jun 6, 2023
commit 83b6905d16fc84abfa00fd4f2d17be7e552242a5
6 changes: 4 additions & 2 deletions speech_recognition/recognizers/fasterwhisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def recognize_faster_whisper(
recognizer,
audio_data: "AudioData",
model="base",
download_root=None,
beam_size=5,
device="auto",
compute_type="int8",
Expand All @@ -29,6 +30,7 @@ def recognize_faster_whisper(
{beam_size}: Allows overriding the default beam size if desired.
{device}: Allows setting the device, e.g. "auto", "cpu", "cuda", etc.
{compute_type}: Allows setting the compute type, e.g. "int8", "float16", etc.
{download_root}: Allows setting the model cache root path

The return dict is also customized to avoid returning a mess of FasterWhisper objects.
"""
Expand All @@ -39,9 +41,9 @@ def recognize_faster_whisper(
import soundfile as sf
import faster_whisper

print(f"model: {model}, beam_size: {beam_size}, device: {device}, compute_type: {compute_type}, language: {language}, translate: {translate}")
print(f"model: {model}, download_root: {download_root}, beam_size: {beam_size}, device: {device}, compute_type: {compute_type}, language: {language}, translate: {translate}")

whisper_model = faster_whisper.WhisperModel(model, device=device, compute_type=compute_type)
whisper_model = faster_whisper.WhisperModel(model, device=device, compute_type=compute_type, download_root=download_root)

# 16 kHz https://github.com/openai/whisper/blob/28769fcfe50755a817ab922a7bc83483159600a9/whisper/audio.py#L98-L99
wav_bytes = audio_data.get_wav_data(convert_rate=16000)
Expand Down