Class: ElevenlabsClient::AudioIsolation

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AudioIsolation

Returns a new instance of AudioIsolation.



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

def initialize(client)
  @client = client
end

Instance Method Details

#isolate(audio_file, filename, **options) ⇒ String

POST /v1/audio-isolation Removes background noise from audio Documentation: https://elevenlabs.io/docs/api-reference/audio-isolation

Parameters:

  • audio_file (IO, File)

    The audio file from which vocals/speech will be isolated

  • filename (String)

    Original filename for the audio file

  • options (Hash)

    Optional parameters

Options Hash (**options):

  • :file_format (String)

    Format of input audio ('pcm_s16le_16' or 'other', defaults to 'other')

Returns:

  • (String)

    Binary audio data with background noise removed



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

def isolate(audio_file, filename, **options)
  endpoint = "/v1/audio-isolation"
  
  payload = {
    audio: @client.file_part(audio_file, filename)
  }
  
  # Add optional parameters if provided
  payload[:file_format] = options[:file_format] if options[:file_format]

  @client.post_multipart(endpoint, payload)
end

#isolate_stream(audio_file, filename, **options, &block) ⇒ Faraday::Response

POST /v1/audio-isolation/stream Removes background noise from audio with streaming response Documentation: https://elevenlabs.io/docs/api-reference/audio-isolation/stream

Parameters:

  • audio_file (IO, File)

    The audio file from which vocals/speech will be isolated

  • filename (String)

    Original filename for the audio file

  • options (Hash)

    Optional parameters

  • block (Proc)

    Block to handle each chunk of streaming audio data

Options Hash (**options):

  • :file_format (String)

    Format of input audio ('pcm_s16le_16' or 'other', defaults to 'other')

Returns:

  • (Faraday::Response)

    Response object for streaming



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/elevenlabs_client/endpoints/audio_isolation.rb', line 41

def isolate_stream(audio_file, filename, **options, &block)
  endpoint = "/v1/audio-isolation/stream"
  
  payload = {
    audio: @client.file_part(audio_file, filename)
  }
  
  # Add optional parameters if provided
  payload[:file_format] = options[:file_format] if options[:file_format]

  # Use streaming multipart request
  response = @client.instance_variable_get(:@conn).post(endpoint) do |req|
    req.headers["xi-api-key"] = @client.api_key
    req.body = payload
    
    # Set up streaming callback if block provided
    if block_given?
      req.options.on_data = proc do |chunk, _|
        block.call(chunk)
      end
    end
  end

  @client.send(:handle_response, response)
end