Created
August 21, 2024 09:42
-
-
Save Terieyenike/742e93e691da014fecd2830d3665b47e to your computer and use it in GitHub Desktop.
Text to Speech (TTS) API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| from dotenv import load_dotenv | |
| from openai import OpenAI | |
| client = OpenAI() | |
| api_key = os.getenv('OPENAI_API_KEY') | |
| text = 'In the future, we may be able to travel to other galaxies using wormholes or warp drives.' | |
| response = client.audio.speech.create( | |
| model="tts-1", | |
| voice="alloy", | |
| input=text | |
| ) | |
| with open('audio/tts-1.mp3', 'wb') as f: | |
| f.write(response.content) | |
| import IPython | |
| IPython.display.Audio('audio/tts-1.mp3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment