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 model.transcribe #1979

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 7 additions & 2 deletions whisper/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ def transcribe(
content_frames = mel.shape[-1] - N_FRAMES
content_duration = float(content_frames * HOP_LENGTH / SAMPLE_RATE)

def maybe_dereference_list(obj: Union[dict, list[dict]]) -> dict:
if isinstance(obj, list):
return obj[0]
return obj

if decode_options.get("language", None) is None:
if not model.is_multilingual:
decode_options["language"] = "en"
Expand All @@ -144,7 +149,7 @@ def transcribe(
)
mel_segment = pad_or_trim(mel, N_FRAMES).to(model.device).to(dtype)
_, probs = model.detect_language(mel_segment)
decode_options["language"] = max(probs, key=probs.get)
decode_options["language"] = max(maybe_dereference_list(probs), key=maybe_dereference_list(probs).get)
if verbose is not None:
print(
f"Detected language: {LANGUAGES[decode_options['language']].title()}"
Expand Down Expand Up @@ -192,7 +197,7 @@ def decode_with_fallback(segment: torch.Tensor) -> DecodingResult:
kwargs.pop("best_of", None)

options = DecodingOptions(**kwargs, temperature=t)
decode_result = model.decode(segment, options)
decode_result = maybe_dereference_list(model.decode(segment, options))

needs_fallback = False
if (
Expand Down
Loading