from elevenlabs import ElevenLabs, PronunciationDictionaryVersionLocator
from elevenlabs.play import play
elevenlabs = ElevenLabs()
with open("dictionary.pls", "rb") as f:
# this dictionary changes how tomato is pronounced
pronunciation_dictionary = elevenlabs.pronunciation_dictionaries.create_from_file(
file=f.read(), name="example"
)
audio_1 = elevenlabs.text_to_speech.convert(
text="Without the dictionary: tomato",
voice_id="aMSt68OGf4xUZAnLpTU8",
model_id="eleven_flash_v2",
)
audio_2 = elevenlabs.text_to_speech.convert(
text="With the dictionary: tomato",
voice_id="aMSt68OGf4xUZAnLpTU8",
model_id="eleven_flash_v2",
pronunciation_dictionary_locators=[
PronunciationDictionaryVersionLocator(
pronunciation_dictionary_id=pronunciation_dictionary.id,
version_id=pronunciation_dictionary.version_id,
)
],
)
# play the audio
play(audio_1)
play(audio_2)