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

fix: transcribe verbosity #140

Merged
merged 1 commit into from
Sep 26, 2022
Merged
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
10 changes: 6 additions & 4 deletions whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def transcribe(
model: "Whisper",
audio: Union[str, np.ndarray, torch.Tensor],
*,
verbose: bool = False,
verbose: Optional[bool] = None,
temperature: Union[float, Tuple[float, ...]] = (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
compression_ratio_threshold: Optional[float] = 2.4,
logprob_threshold: Optional[float] = -1.0,
Expand All @@ -40,7 +40,8 @@ def transcribe(
The path to the audio file to open, or the audio waveform

verbose: bool
Whether to display the text being decoded to the console
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

temperature: Union[float, Tuple[float, ...]]
Temperature for sampling. It can be a tuple of temperatures, which will be successfully used
Expand Down Expand Up @@ -88,7 +89,8 @@ def transcribe(
segment = pad_or_trim(mel, N_FRAMES).to(model.device).to(dtype)
_, probs = model.detect_language(segment)
decode_options["language"] = max(probs, key=probs.get)
print(f"Detected language: {LANGUAGES[decode_options['language']].title()}")
if verbose is not None:
print(f"Detected language: {LANGUAGES[decode_options['language']].title()}")

mel = mel.unsqueeze(0)
language = decode_options["language"]
Expand Down Expand Up @@ -170,7 +172,7 @@ def add_segment(
num_frames = mel.shape[-1]
previous_seek_value = seek

with tqdm.tqdm(total=num_frames, unit='frames', disable=verbose) as pbar:
with tqdm.tqdm(total=num_frames, unit='frames', disable=verbose is not False) as pbar:
while seek < num_frames:
timestamp_offset = float(seek * HOP_LENGTH / SAMPLE_RATE)
segment = pad_or_trim(mel[:, :, seek:], N_FRAMES).to(model.device).to(dtype)
Expand Down