Skip to content

Instantly share code, notes, and snippets.

@Terieyenike
Created August 21, 2024 09:42
Show Gist options
  • Select an option

  • Save Terieyenike/742e93e691da014fecd2830d3665b47e to your computer and use it in GitHub Desktop.

Select an option

Save Terieyenike/742e93e691da014fecd2830d3665b47e to your computer and use it in GitHub Desktop.
Text to Speech (TTS) API
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