Skip to content

Report the language code when transcribe() is given a language name - #2891

Open
RaphaelFakhri wants to merge 1 commit into
openai:mainfrom
RaphaelFakhri:fix-language-name-result
Open

RaphaelFakhri wants to merge 1 commit into
openai:mainfrom
RaphaelFakhri:fix-language-name-result

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

The CLI accepts language names for --language (for example --language Japanese), and transcribe() accepts them too, because get_tokenizer() maps names to codes. The tokenizer and decoder then use the code, but transcribe() returns the original string, so result["language"] is "Japanese" instead of "ja", and "EN" stays "EN". The JSON output carries the same value. When the language is detected, or given as a lowercase code, the result holds a code, so anything that reads result["language"] sees two different formats.

Changes

  • transcribe() now lowercases the requested language and maps a name to its code through TO_LANGUAGE_CODE before it builds the tokenizer, and stores that code in decode_options. A name such as "English" or "english" and a code in any case such as "EN" all produce "en". Unsupported values still raise the same ValueError from get_tokenizer().
  • Adds test_language_is_reported_as_a_code, which transcribes jfk.flac with the tiny model using language="English" and language="EN", and checks that result["language"] == "en".

Reproduce

whisper tests/jfk.flac --model tiny --language English -f json -o out --fp16 False
python -c "import json; print(json.load(open('out/jfk.json'))['language'])"

Before: English. After: en.

Testing

  • The new test fails on main (assert 'English' == 'en', assert 'EN' == 'en') and passes with this change.
  • pytest -k 'not test_transcribe or test_transcribe[tiny] or test_transcribe[tiny.en]' -m 'not requires_cuda' passes.
  • black, isort, and flake8 with the pre-commit settings report no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant