Class: OpenAI::Models::Audio::SpeechCreateParams

Inherits:
Internal::Type::BaseModel show all
Extended by:
Internal::Type::RequestParameters::Converter
Includes:
Internal::Type::RequestParameters
Defined in:
lib/openai/models/audio/speech_create_params.rb,
sig/openai/models/audio/speech_create_params.rbs

Overview

See Also:

  • OpenAI::Resources::Audio::Speech#create

Defined Under Namespace

Modules: Model, ResponseFormat, StreamFormat, Voice

Instance Attribute Summary collapse

Attributes included from Internal::Type::RequestParameters

#request_options

Attributes inherited from Internal::Type::BaseModel

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Internal::Type::RequestParameters::Converter

dump_request

Methods included from Internal::Type::RequestParameters

included

Methods inherited from Internal::Type::BaseModel

==, #==, #[], #_request_id, #_set_last_response, coerce, #deconstruct_keys, #deep_to_h, dump, #encode_with, fields, hash, #hash, inherited, #inspect, inspect, known_fields, optional, recursively_to_h, required, #to_h, #to_json, #to_s, to_sorbet_type, #to_yaml

Methods included from Internal::Type::Converter

#coerce, coerce, coerce_cached, coerce_with_error, #dump, dump, #inspect, inspect, meta_info, new_coerce_state, resolve_type, type_info

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(input:, model:, voice:, instructions: nil, response_format: nil, speed: nil, stream_format: nil, request_options: {}) ⇒ SpeechCreateParams

Returns a new instance of SpeechCreateParams.

Parameters:

  • input —

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

  • model —

    One of the available TTS models: tts-1, tts-1-hd, gpt-4o-mini-tts, or gpt-4o-mini-tts-2025-12-15.

  • voice —

    The voice to use when generating the audio. Supported built-in voices are alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse, marin, and cedar. You may also provide a custom voice object with an id, for example { "id": "voice_1234" }. Previews of the voices are available in the Text to speech guide. Custom voices must be created from audio samples. Voices created from text prompts are supported only in Live.

  • instructions (defaults to: nil) —

    Control the voice of your generated audio with additional instructions. Does not work with tts-1 or tts-1-hd.

  • response_format (defaults to: nil) —

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

  • speed (defaults to: nil) —

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

  • stream_format (defaults to: nil) —

    The format to stream the audio in. Supported formats are sse and audio. sse is not supported for tts-1 or tts-1-hd.

  • input: (String)
  • model: (OpenAI::Models::Audio::SpeechCreateParams::model)
  • voice: (OpenAI::Models::Audio::SpeechCreateParams::voice, { id: String })
  • instructions: (String) (defaults to: nil)
  • response_format: (OpenAI::Models::Audio::SpeechCreateParams::response_format) (defaults to: nil)
  • speed: (Float) (defaults to: nil)
  • stream_format: (OpenAI::Models::Audio::SpeechCreateParams::stream_format) (defaults to: nil)
  • request_options: (OpenAI::request_opts) (defaults to: {})


# File 'lib/openai/models/audio/speech_create_params.rb', line 66

Instance Attribute Details

#input ⇒ String

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

Returns:

  • (String)


15
# File 'lib/openai/models/audio/speech_create_params.rb', line 15

required :input, String

#instructions ⇒ String?

Control the voice of your generated audio with additional instructions. Does not work with tts-1 or tts-1-hd.

Returns:

  • (String, nil)


43
# File 'lib/openai/models/audio/speech_create_params.rb', line 43

optional :instructions, String

#model ⇒ OpenAI::Models::Audio::SpeechCreateParams::model

One of the available TTS models: tts-1, tts-1-hd, gpt-4o-mini-tts, or gpt-4o-mini-tts-2025-12-15.

Returns:

  • (OpenAI::Models::Audio::SpeechCreateParams::model)


23
# File 'lib/openai/models/audio/speech_create_params.rb', line 23

required :model, union: -> { OpenAI::Audio::SpeechCreateParams::Model }

#response_format ⇒ OpenAI::Models::Audio::SpeechCreateParams::response_format?

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

Returns:

  • (OpenAI::Models::Audio::SpeechCreateParams::response_format, nil)


50
# File 'lib/openai/models/audio/speech_create_params.rb', line 50

optional :response_format, enum: -> { OpenAI::Audio::SpeechCreateParams::ResponseFormat }

#speed ⇒ Float?

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

Returns:

  • (Float, nil)


57
# File 'lib/openai/models/audio/speech_create_params.rb', line 57

optional :speed, Float

#stream_format ⇒ OpenAI::Models::Audio::SpeechCreateParams::stream_format?

The format to stream the audio in. Supported formats are sse and audio. sse is not supported for tts-1 or tts-1-hd.

Returns:

  • (OpenAI::Models::Audio::SpeechCreateParams::stream_format, nil)


64
# File 'lib/openai/models/audio/speech_create_params.rb', line 64

optional :stream_format, enum: -> { OpenAI::Audio::SpeechCreateParams::StreamFormat }

#voice ⇒ OpenAI::Models::Audio::SpeechCreateParams::voice

The voice to use when generating the audio. Supported built-in voices are alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse, marin, and cedar. You may also provide a custom voice object with an id, for example { "id": "voice_1234" }. Previews of the voices are available in the Text to speech guide. Custom voices must be created from audio samples. Voices created from text prompts are supported only in Live.

Returns:

  • (OpenAI::Models::Audio::SpeechCreateParams::voice)


36
# File 'lib/openai/models/audio/speech_create_params.rb', line 36

required :voice, union: -> { OpenAI::Audio::SpeechCreateParams::Voice }

Class Method Details

.values ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)


# File 'lib/openai/models/audio/speech_create_params.rb', line 218

.variants ⇒ Array(String, Symbol, OpenAI::Models::Audio::SpeechModel)

Returns:



# File 'lib/openai/models/audio/speech_create_params.rb', line 114

Instance Method Details

#to_hash ⇒ { input: String, model: OpenAI::Models::Audio::SpeechCreateParams::model, voice: OpenAI::Models::Audio::SpeechCreateParams::voice, ?instructions: String, ?response_format: OpenAI::Models::Audio::SpeechCreateParams::response_format, ?speed: Float, ?stream_format: OpenAI::Models::Audio::SpeechCreateParams::stream_format, ?request_options: OpenAI::RequestOptions }

Returns:

  • ({ input: String, model: OpenAI::Models::Audio::SpeechCreateParams::model, voice: OpenAI::Models::Audio::SpeechCreateParams::voice, ?instructions: String, ?response_format: OpenAI::Models::Audio::SpeechCreateParams::response_format, ?speed: Float, ?stream_format: OpenAI::Models::Audio::SpeechCreateParams::stream_format, ?request_options: OpenAI::RequestOptions })


125
126
127
128
129
130
131
132
133
134
# File 'sig/openai/models/audio/speech_create_params.rbs', line 125

def to_hash: -> {
  input: String,
  model: OpenAI::Models::Audio::SpeechCreateParams::model,
  voice: OpenAI::Models::Audio::SpeechCreateParams::voice,
  ?instructions: String,
  ?response_format: OpenAI::Models::Audio::SpeechCreateParams::response_format,
  ?speed: Float,
  ?stream_format: OpenAI::Models::Audio::SpeechCreateParams::stream_format,
  ?request_options: OpenAI::RequestOptions
}