Skip to content

Commit d18e9ea

Browse files
committed
transcribe() on English-only model won't complain when language="en" is not given
1 parent 82725ce commit d18e9ea

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

whisper/transcribe.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ def transcribe(
8484
mel = log_mel_spectrogram(audio)
8585

8686
if decode_options.get("language", None) is None:
87-
if verbose:
88-
print("Detecting language using up to the first 30 seconds. Use `--language` to specify the language")
89-
segment = pad_or_trim(mel, N_FRAMES).to(model.device).to(dtype)
90-
_, probs = model.detect_language(segment)
91-
decode_options["language"] = max(probs, key=probs.get)
92-
if verbose is not None:
93-
print(f"Detected language: {LANGUAGES[decode_options['language']].title()}")
87+
if not model.is_multilingual:
88+
decode_options["language"] = "en"
89+
else:
90+
if verbose:
91+
print("Detecting language using up to the first 30 seconds. Use `--language` to specify the language")
92+
segment = pad_or_trim(mel, N_FRAMES).to(model.device).to(dtype)
93+
_, probs = model.detect_language(segment)
94+
decode_options["language"] = max(probs, key=probs.get)
95+
if verbose is not None:
96+
print(f"Detected language: {LANGUAGES[decode_options['language']].title()}")
9497

9598
language = decode_options["language"]
9699
task = decode_options.get("task", "transcribe")
@@ -282,7 +285,8 @@ def cli():
282285
os.makedirs(output_dir, exist_ok=True)
283286

284287
if model_name.endswith(".en") and args["language"] not in {"en", "English"}:
285-
warnings.warn(f"{model_name} is an English-only model but receipted '{args['language']}'; using English instead.")
288+
if args["language"] is not None:
289+
warnings.warn(f"{model_name} is an English-only model but receipted '{args['language']}'; using English instead.")
286290
args["language"] = "en"
287291

288292
temperature = args.pop("temperature")

0 commit comments

Comments
 (0)