How native language prompting works
By default, the model looks at your text and guesses the native language for your generated speech. But you can explicitly prompt the model for more control.
This shapes the accent and how the model handles foreign words.
import asyncio
from lmnt import AsyncLmnt
async def main():
client = AsyncLmnt()
text = 'Hello, and uh, welcome to the show.'
for language in ['en', 'fr', 'de']:
async with client.speech.with_streaming_response.generate(
text=text,
voice='leah',
language=language,
) as response:
await response.stream_to_file(f'{language}.mp3')
asyncio.run(main())de.mp3
en.mp3
fr.mp3
The output:
en.mp3→ spoken by a native English speaker.fr.mp3→ spoken in English with a French accent.de.mp3→ spoken in English with a German accent.
Code switching
Code switching is mixing text from two or more of the model's supported languages into the same text prompt, and is fully supported.
import asyncio
from lmnt import AsyncLmnt
async def main():
client = AsyncLmnt()
text = 'Bonjour! Did you know that mariposa means butterfly in Spanish?'
for language in ['en', 'fr', 'es']:
async with client.speech.with_streaming_response.generate(
text=text,
voice='leah',
language=language,
) as response:
await response.stream_to_file(f'{language}.mp3')
asyncio.run(main())en.mp3
es.mp3
fr.mp3
The output:
en.mp3→ English speaker —Bonjourandmariposasound foreign.fr.mp3→ French speaker —butterflyandmariposasound foreign.es.mp3→ Spanish speaker —Bonjourandbutterflysound foreign.
Use native scripts
Our models have been trained on native scripts for all supported languages.
For languages with non-Latin scripts, write your text in the language's native script. Romanized or transliterated text may not always be pronounced as you'd expect.
Supported languages
| Language | Code |
|---|---|
| Arabic | ar |
| Assamese | as |
| Bengali | bn |
| Chinese | zh |
| Czech | cs |
| Danish | da |
| Dutch | nl |
| English | en |
| Finnish | fi |
| French | fr |
| German | de |
| Hindi | hi |
| Indonesian | id |
| Italian | it |
| Japanese | ja |
| Korean | ko |
| Malayalam | ml |
| Marathi | mr |
| Polish | pl |
| Portuguese | pt |
| Russian | ru |
| Slovak | sk |
| Spanish | es |
| Swedish | sv |
| Tamil | ta |
| Telugu | te |
| Thai | th |
| Turkish | tr |
| Ukrainian | uk |
| Urdu | ur |
| Vietnamese | vi |