CommencerCommencer gratuitement

OpenAI's text-to-speech (TTS)

OpenAI now provide models for creating human-like speech from a text input, so-called text-to-speech or TTS. OpenAI provide several voices to choose from, and they provide the ability to stream the response to local files or downstream applications.

Cet exercice fait partie du cours

Multi-Modal Systems with the OpenAI API

Afficher le cours

Instructions

  • Create the text-to-speech request for "Hi! How's your day going?", using the "ballad" voice.
  • Stream the response to an .mp3 file.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

client = OpenAI(api_key="")

# Create the text-to-speech request
response = client.audio.speech.create(
  model="gpt-4o-mini-tts",
  ____,
  input="Hi! How's your day going?"
)

# Stream the response to an MP3 file
response.____("output.mp3")
Modifier et exécuter le code