Class: ElevenlabsClient::ForcedAlignment

Inherits:
Object
  • Object
show all
Defined in:
lib/elevenlabs_client/endpoints/forced_alignment.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ForcedAlignment

Returns a new instance of ForcedAlignment.



5
6
7
# File 'lib/elevenlabs_client/endpoints/forced_alignment.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(audio_file, filename, text, **options) ⇒ Hash Also known as: align, force_align

POST /v1/forced-alignment Force align an audio file to text. Get timing information for each character and word Documentation: https://elevenlabs.io/docs/api-reference/forced-alignment

Parameters:

  • audio_file (IO, File)

    The audio file to align (must be less than 1GB)

  • filename (String)

    Original filename for the audio file

  • text (String)

    The text to align with the audio

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :enabled_spooled_file (Boolean)

    Stream file in chunks for large files (defaults to false)

Returns:

  • (Hash)

    JSON response containing characters, words arrays with timing info, and loss score



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/elevenlabs_client/endpoints/forced_alignment.rb', line 19

def create(audio_file, filename, text, **options)
  endpoint = "/v1/forced-alignment"
  
  payload = {
    file: @client.file_part(audio_file, filename),
    text: text
  }
  
  # Add optional parameters if provided
  payload[:enabled_spooled_file] = options[:enabled_spooled_file] unless options[:enabled_spooled_file].nil?

  @client.post_multipart(endpoint, payload)
end