glopenai/audio

Types

Request to generate speech from text.

pub type CreateSpeechRequest {
  CreateSpeechRequest(
    input: String,
    model: SpeechModel,
    voice: Voice,
    instructions: option.Option(String),
    response_format: option.Option(SpeechResponseFormat),
    speed: option.Option(Float),
    stream_format: option.Option(StreamFormat),
  )
}

Constructors

TTS model selection.

pub type SpeechModel {
  Tts1
  Tts1Hd
  Gpt4oMiniTts
  OtherSpeechModel(String)
}

Constructors

  • Tts1
  • Tts1Hd
  • Gpt4oMiniTts
  • OtherSpeechModel(String)

Audio output format for speech synthesis.

pub type SpeechResponseFormat {
  Mp3
  Opus
  Aac
  Flac
  Pcm
  Wav
}

Constructors

  • Mp3
  • Opus
  • Aac
  • Flac
  • Pcm
  • Wav

Format for streaming audio output.

pub type StreamFormat {
  Sse
  Audio
}

Constructors

  • Sse
  • Audio

Voice options for text-to-speech. Includes built-in voices and custom voice references.

pub type Voice {
  Alloy
  Ash
  Ballad
  Coral
  Echo
  Fable
  Onyx
  Nova
  Sage
  Shimmer
  Verse
  Marin
  Cedar
  CustomVoice(id: String)
  OtherVoice(String)
}

Constructors

  • Alloy
  • Ash
  • Ballad
  • Coral
  • Echo
  • Fable
  • Onyx
  • Nova
  • Sage
  • Shimmer
  • Verse
  • Marin
  • Cedar
  • CustomVoice(id: String)

    A custom voice referenced by its ID (e.g. “voice_1234”).

  • OtherVoice(String)

Values

pub fn create_speech_request(
  config: config.Config,
  params: CreateSpeechRequest,
) -> request.Request(String)

Build a request to generate speech audio from text. The response body is raw audio bytes — the user’s HTTP client should return the body as a BitArray (not String) for binary audio data.

pub fn create_speech_request_to_json(
  request: CreateSpeechRequest,
) -> json.Json
pub fn create_speech_response(
  response: response.Response(String),
) -> Result(String, error.GlopenaiError)

The speech endpoint returns raw audio bytes, not JSON. The user should read the response body directly from their HTTP client. This function is provided only for checking error responses (non-2xx status codes).

pub fn new_create_speech_request(
  input input: String,
  model model: SpeechModel,
  voice voice: Voice,
) -> CreateSpeechRequest

Create a new speech request with the required fields.

pub fn speech_model_decoder() -> decode.Decoder(SpeechModel)
pub fn speech_model_to_json(model: SpeechModel) -> json.Json
pub fn speech_response_format_decoder() -> decode.Decoder(
  SpeechResponseFormat,
)
pub fn speech_response_format_to_json(
  format: SpeechResponseFormat,
) -> json.Json
pub fn stream_format_decoder() -> decode.Decoder(StreamFormat)
pub fn stream_format_to_json(format: StreamFormat) -> json.Json
pub fn voice_decoder() -> decode.Decoder(Voice)
pub fn voice_to_json(voice: Voice) -> json.Json
pub fn with_instructions(
  request: CreateSpeechRequest,
  instructions: String,
) -> CreateSpeechRequest
pub fn with_speed(
  request: CreateSpeechRequest,
  speed: Float,
) -> CreateSpeechRequest
pub fn with_stream_format(
  request: CreateSpeechRequest,
  format: StreamFormat,
) -> CreateSpeechRequest
Search Document