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

[FEATURE_REQUEST] Add transcribe vad params #227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
26 changes: 25 additions & 1 deletion whisper_timestamped/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def transcribe_timestamped(
suppress_tokens="-1",
sample_len=None,
verbose=False,
avoid_empty_speech=True,
vad_min_speech_duration=0.1,
vad_min_silence_duration=1,
vad_dilatation=0.5,
):
"""
Transcribe an audio file using Whisper
Expand Down Expand Up @@ -214,6 +218,18 @@ def transcribe_timestamped(
Whether to display the text being decoded to the console. If True, displays all the details,
If False, displays minimal details. If None, does not display anything

avoid_empty_speech: bool
Whether to avoid empty speech segments (i.e. segments with no speech detected).

vad_min_speech_duration: float
Minimum duration of a speech segment, in seconds. If a speech segment is shorter than this, it will be removed.

vad_min_silence_duration: float
Minimum duration of a silence segment, in seconds. If a silence segment is shorter than this, it will be removed.

vad_dilatation: float
Dilatation factor for the speech segments. If a speech segment is shorter than this, it will be removed.

Returns
-------
A dictionary containing the resulting text ("text") and segment-level details ("segments"), and
Expand Down Expand Up @@ -293,7 +309,15 @@ def transcribe_timestamped(

if vad is not None:
audio = get_audio_tensor(audio)
audio, vad_segments, convert_timestamps = remove_non_speech(audio, method=vad, sample_rate=SAMPLE_RATE, plot=plot_word_alignment, avoid_empty_speech=True)
audio, vad_segments, convert_timestamps = remove_non_speech(audio,
method=vad,
sample_rate=SAMPLE_RATE,
plot=plot_word_alignment,
avoid_empty_speech=avoid_empty_speech,
min_speech_duration=vad_min_speech_duration,
min_silence_duration=vad_min_silence_duration,
dilatation=vad_dilatation,
)
else:
vad_segments = None

Expand Down