This is a minimal reproducible example demonstrating an issue with AssemblyAI's code switching feature for English/French bilingual audio.
When transcribing Canadian Parliament floor audio (which contains both English and French), the transcription appears to only return English text, with French portions being omitted or removed.
- Add your AssemblyAI API key to the
.envfile:
ASSEMBLYAI_API_KEY='your-api-key-here'- Install dependencies with pipenv:
pipenv install- Activate the pipenv environment:
pipenv shell- Run the demo:
python assemblyai_code_switching_demo.pyThe audio file contains mixed English and French speech from Canadian Parliament proceedings. With code switching enabled, we expect:
- Both English and French utterances to be transcribed
language_codeattribute on utterances indicating "en" or "fr"- Full transcript containing both languages
Only French text appears in the transcript, with English portions missing or removed.
URL: https://twocapitals.ca/assets/floor-audio-test.m4a
This is floor audio from Canadian Parliament, which naturally contains both English and French as both are official languages.
- AssemblyAI Python SDK: 0.45.4
- Python: 3.11+
- Audio format: M4A
- Languages: English (en) + French (fr)
According to AssemblyAI documentation, code switching can be enabled in two ways:
- Manual: Set
language_codesto a list of two language codes (one must be 'en'), e.g.,["en", "fr"] - Automatic: Enable
language_detection=Trueand setcode_switching=Truewithinlanguage_detection_options
However, the English-French language pair is not listed as one of the "optimal" pairs (only English-Spanish and English-German are listed as optimal). For other language combinations, the documentation notes that optimal results typically require the non-English language to be dominant in the audio.
Reference: https://www.assemblyai.com/docs/pre-recorded-audio/code-switching