#text to voice api
1 messages · Page 1 of 1 (latest)
Hi @rustic mortar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
OpenAI provides a Text-to-Speech (TTS) API that allows developers to generate high-quality spoken audio from text. The API provides a speech endpoint based on the TTS model. It comes with 6 built-in voices and can be used for various applications such as narrating a blog post, producing spoken audio in multiple languages, and giving real-time audio output using streaming.
Here is a simple Python example of how to use the API to generate spoken audio from input text:
from pathlib import Path
from openai import OpenAI
client = OpenAI()
speech_file_path = Path(__file__).parent / "speech.mp3"
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="Today is a wonderful day to build something people love!"
)
response.stream_to_file(speech_file_path)
In this example, the speech endpoint takes in three key inputs: the model, the text that should be turned into audio, and the voice to be used for the audio generation. The model parameter can be either tts-1 or tts-1-hd, with the former optimized for real-time use cases and the latter optimized for quality. The voice parameter can be one of the six built-in voices: alloy, echo, fable, onyx, nova, and shimmer.
As for the "Advanced Voice Mode" that you mentioned, it is a feature of the GPT-4o model and is currently not available through the API. It is expected to start rolling out to a select group of users in late July and be available to all ChatGPT Plus customers in Fall. However, there's no current way to control the emotion reliably.
Please note that OpenAI's usage policies require you to provide a clear disclosure to end users that the TTS voice they are hearing is AI-generated and not a human voice.
For more information, you can refer to the OpenAI Text-to-Speech Guide (https://platform.openai.com/docs/guides/text-to-speech) and the OpenAI API Reference (https://platform.openai.com/docs/api-reference/audio/createSpeech).
Sources:
- OpenAI Text-to-Speech Guide (https://platform.openai.com/docs/guides/text-to-speech)
- OpenAI API Reference (https://platform.openai.com/docs/api-reference/audio/createSpeech)
- OpenAI Community Post (https://community.openai.com/t/846704)