OpenAI Text-to-Speech (TTS) – I Tried the Top Ten Languages (10 Speech Samples) : Chris
by: Chris
blow post content copied from Be on the Right Side of Change
click here to view original post
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.
November 14, 2023 at 03:48PM
Click here for more details...
=============================
The original post is available in Be on the Right Side of Change by Chris
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================
Post a Comment