Class: GroqRuby::Resources::Audio::Speech

Inherits:
Base
  • Object
show all
Defined in:
lib/groq_ruby/resources/audio/speech.rb

Overview

‘client.audio.speech.create(…)` — text-to-speech. Returns the raw audio bytes (caller decides where to write them).

Constant Summary collapse

PATH =
"/openai/v1/audio/speech".freeze
SCHEMA =
Dry::Schema.define do
  required(:input).filled(:string)
  required(:model).filled(:string)
  required(:voice).filled(:string)
  optional(:response_format).filled(:string, included_in?: %w[flac mp3 mulaw ogg wav])
  optional(:sample_rate).filled(:integer, included_in?: [8000, 16000, 22050, 24000, 32000, 44100, 48000])
  optional(:speed).filled(:float)
end

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GroqRuby::Resources::Base

Instance Method Details

#create(**params) ⇒ String

Returns raw audio bytes — write with ‘File.binwrite`.

Parameters:

  • params (Hash)

    required: ‘:input` (text), `:model`, `:voice`. Optional: `:response_format` (`“flac”` | `“mp3”` | `“mulaw”` | `“ogg”` | `“wav”`), `:sample_rate`, `:speed`.

Returns:

  • (String)

    raw audio bytes — write with ‘File.binwrite`.

Raises:



25
26
27
28
# File 'lib/groq_ruby/resources/audio/speech.rb', line 25

def create(**params)
  body = validate!(SCHEMA, params)
  perform(Request.new(method: :post, path: PATH, body: body), accept: :binary)
end