OpenAI Text-to-Speech (TTS) – I Tried the Top Ten Languages with 10 Amazing Speech Samples

4.7/5 - (4 votes)

Let’s check out OpenAI’s fantastic Text-to-Speech (TTS) technology. I was blown away when I first heard these voices; they sound so incredibly human, it’s almost hard to believe!

It’s like having a friendly chat in different languages, all thanks to OpenAI’s amazing speech-generation skills in the world’s top ten languages.

I used the following code:

import openai

your_openai_key = 'sk-...'
d = {
    'English': 'Finxter helps you stay on the right side of change!',
    'Mandarin Chinese (Simplified)': '...',
    'Hindi': '...',
    'Spanish': '¡Finxter te ayuda a mantenerte del lado correcto del cambio!',
    'French': 'Finxter vous aide à rester du bon côté du changement !',
    'Arabic': '...',
    'Bengali': '...',
    'Russian': 'Финкстер помогает вам оставаться на правильной стороне изменений!',
    'Portuguese': 'Finxter ajuda você a permanecer no lado certo da mudança!',
    'Indonesian': 'Finxter membantu Anda tetap di sisi yang benar dari perubahan!'
}


client = openai.OpenAI(api_key=your_openai_key)
voices = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']

for language in d:
    response = client.audio.speech.create(
        model="tts-1",
        voice='onyx',
        input=d[language]
    )

    response.stream_to_file(f'{language}.mp3')

This code snippet uses OpenAI’s Text-to-Speech (TTS) capabilities through the OpenAI Python library. It begins by importing the OpenAI module and setting up an API key. You should have installed OpenAI:

🧑‍💻 Recommended: How to Install OpenAI in Python?

A dictionary d is defined, containing sentences in various languages, each associated with a language key. I used the world’s 10 most spoken languages but for formatting reasons skipped some translations — my blog software cannot display the Unicode symbols.

The code then initializes an OpenAI client with the specified API key. It iterates over the languages in the dictionary d, using the client.audio.speech.create function to convert the text in each language to speech.

The chosen model for TTS is "tts-1" and the voice is set to ‘onyx’ for all languages.

The audio output for each language is then saved as an MP3 file named after the respective language. Here are the language samples — look at how amazing these sound: 👇


English: Finxter helps you stay on the right side of change!


Mandarin Chinese (Simplified): Finxter 帮助你保持在变化的正确一边!


Hindi: फिंक्सटर आपको परिवर्तन के सही पक्ष में बने रहने में मदद करता है!


Spanish: ¡Finxter te ayuda a mantenerte del lado correcto del cambio!


French: Finxter vous aide à rester du bon côté du changement !


Arabic: فينكستر يساعدك على البقاء على الجانب الصحيح من التغيير!


Bengali: ফিন্ক্সটার আপনাকে পরিবর্তনের সঠিক দিকে থাকতে সাহায্য করে!


Russian: Финкстер помогает вам оставаться на правильной стороне изменений!


Portuguese: Finxter ajuda você a permanecer no lado certo da mudança!


Indonesian: Finxter membantu Anda tetap di sisi yang benar dari perubahan!


Bonus – German: Finxter hilft dir, auf der richtigen Seite der Veränderung zu bleiben.


Thanks for being an avid Finxter reader! Check out this article next: 👇

🧑‍💻 Recommended: OpenAI Text to Speech (TTS): Minimal Example in Python

Feel free to check out our academy courses to keep mastering prompt engineering, e.g., with Llama 2:

Prompt Engineering with Llama 2

💡 The Llama 2 Prompt Engineering course helps you stay on the right side of change. Our course is meticulously designed to provide you with hands-on experience through genuine projects.

You’ll delve into practical applications such as book PDF querying, payroll auditing, and hotel review analytics. These aren’t just theoretical exercises; they’re real-world challenges that businesses face daily.

By studying these projects, you’ll gain a deeper comprehension of how to harness the power of Llama 2 using 🐍 Python, 🔗🦜 Langchain, 🌲 Pinecone, and a whole stack of highly ⚒️🛠️ practical tools of exponential coders in a post-ChatGPT world.