Skip to content

speech

Classes:

Name Description
AsyncSpeech
AsyncSpeechWithRawResponse
AsyncSpeechWithStreamingResponse
Speech
SpeechWithRawResponse
SpeechWithStreamingResponse

AsyncSpeech

AsyncSpeech(client: AsyncOpenAI)

Methods:

Name Description
create

Generates audio from the input text.

with_raw_response
with_streaming_response

create async

create(
    *,
    input: str,
    model: Union[str, Literal["tts-1", "tts-1-hd"]],
    voice: Literal[
        "alloy", "echo", "fable", "onyx", "nova", "shimmer"
    ],
    response_format: (
        Literal["mp3", "opus", "aac", "flac", "wav", "pcm"]
        | NotGiven
    ) = NOT_GIVEN,
    speed: float | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> HttpxBinaryResponseContent

Generates audio from the input text.

Parameters:

Name Type Description Default
input str

The text to generate audio for. The maximum length is 4096 characters.

required
model Union[str, Literal['tts-1', 'tts-1-hd']]

One of the available TTS models: tts-1 or tts-1-hd

required
voice Literal['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']

The voice to use when generating the audio. Supported voices are alloy, echo, fable, onyx, nova, and shimmer. Previews of the voices are available in the Text to speech guide.

required
response_format Literal['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] | NotGiven

The format to audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm.

NOT_GIVEN
speed float | NotGiven

The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> AsyncSpeechWithRawResponse

with_streaming_response

with_streaming_response() -> (
    AsyncSpeechWithStreamingResponse
)

AsyncSpeechWithRawResponse

AsyncSpeechWithRawResponse(speech: AsyncSpeech)

Attributes:

Name Type Description
create

create instance-attribute

create = async_to_raw_response_wrapper(create)

AsyncSpeechWithStreamingResponse

AsyncSpeechWithStreamingResponse(speech: AsyncSpeech)

Attributes:

Name Type Description
create

create instance-attribute

create = async_to_custom_streamed_response_wrapper(
    create, AsyncStreamedBinaryAPIResponse
)

Speech

Speech(client: OpenAI)

Methods:

Name Description
create

Generates audio from the input text.

with_raw_response
with_streaming_response

create

create(
    *,
    input: str,
    model: Union[str, Literal["tts-1", "tts-1-hd"]],
    voice: Literal[
        "alloy", "echo", "fable", "onyx", "nova", "shimmer"
    ],
    response_format: (
        Literal["mp3", "opus", "aac", "flac", "wav", "pcm"]
        | NotGiven
    ) = NOT_GIVEN,
    speed: float | NotGiven = NOT_GIVEN,
    extra_headers: Headers | None = None,
    extra_query: Query | None = None,
    extra_body: Body | None = None,
    timeout: float | Timeout | None | NotGiven = NOT_GIVEN
) -> HttpxBinaryResponseContent

Generates audio from the input text.

Parameters:

Name Type Description Default
input str

The text to generate audio for. The maximum length is 4096 characters.

required
model Union[str, Literal['tts-1', 'tts-1-hd']]

One of the available TTS models: tts-1 or tts-1-hd

required
voice Literal['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer']

The voice to use when generating the audio. Supported voices are alloy, echo, fable, onyx, nova, and shimmer. Previews of the voices are available in the Text to speech guide.

required
response_format Literal['mp3', 'opus', 'aac', 'flac', 'wav', 'pcm'] | NotGiven

The format to audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm.

NOT_GIVEN
speed float | NotGiven

The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default.

NOT_GIVEN
extra_headers Headers | None

Send extra headers

None
extra_query Query | None

Add additional query parameters to the request

None
extra_body Body | None

Add additional JSON properties to the request

None
timeout float | Timeout | None | NotGiven

Override the client-level default timeout for this request, in seconds

NOT_GIVEN

with_raw_response

with_raw_response() -> SpeechWithRawResponse

with_streaming_response

with_streaming_response() -> SpeechWithStreamingResponse

SpeechWithRawResponse

SpeechWithRawResponse(speech: Speech)

Attributes:

Name Type Description
create

create instance-attribute

create = to_raw_response_wrapper(create)

SpeechWithStreamingResponse

SpeechWithStreamingResponse(speech: Speech)

Attributes:

Name Type Description
create

create instance-attribute

create = to_custom_streamed_response_wrapper(
    create, StreamedBinaryAPIResponse
)