Class: ElevenlabsClient::SpeechToSpeech
- Inherits:
-
Object
- Object
- ElevenlabsClient::SpeechToSpeech
- Defined in:
- lib/elevenlabs_client/endpoints/speech_to_speech.rb
Instance Method Summary collapse
-
#convert(voice_id, audio_file, filename, **options) ⇒ String
(also: #voice_changer)
POST /v1/speech-to-speech/:voice_id Transform audio from one voice to another.
-
#convert_stream(voice_id, audio_file, filename, **options, &block) ⇒ Faraday::Response
(also: #voice_changer_stream)
POST /v1/speech-to-speech/:voice_id/stream Stream audio from one voice to another.
-
#initialize(client) ⇒ SpeechToSpeech
constructor
A new instance of SpeechToSpeech.
Constructor Details
#initialize(client) ⇒ SpeechToSpeech
Returns a new instance of SpeechToSpeech.
5 6 7 |
# File 'lib/elevenlabs_client/endpoints/speech_to_speech.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#convert(voice_id, audio_file, filename, **options) ⇒ String Also known as: voice_changer
POST /v1/speech-to-speech/:voice_id Transform audio from one voice to another. Maintain full control over emotion, timing and delivery. Documentation: https://elevenlabs.io/docs/api-reference/speech-to-speech
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elevenlabs_client/endpoints/speech_to_speech.rb', line 26 def convert(voice_id, audio_file, filename, **) endpoint = "/v1/speech-to-speech/#{voice_id}" # Build query parameters query_params = {} query_params[:enable_logging] = [:enable_logging] unless [:enable_logging].nil? query_params[:optimize_streaming_latency] = [:optimize_streaming_latency] if [:optimize_streaming_latency] query_params[:output_format] = [:output_format] if [:output_format] # Add query parameters to endpoint if any exist if query_params.any? query_string = query_params.map { |k, v| "#{k}=#{v}" }.join("&") endpoint += "?#{query_string}" end # Build multipart payload payload = { audio: @client.file_part(audio_file, filename) } # Add optional form parameters payload[:model_id] = [:model_id] if [:model_id] payload[:voice_settings] = [:voice_settings] if [:voice_settings] payload[:seed] = [:seed] if [:seed] payload[:remove_background_noise] = [:remove_background_noise] unless [:remove_background_noise].nil? payload[:file_format] = [:file_format] if [:file_format] @client.post_multipart(endpoint, payload) end |
#convert_stream(voice_id, audio_file, filename, **options, &block) ⇒ Faraday::Response Also known as: voice_changer_stream
POST /v1/speech-to-speech/:voice_id/stream Stream audio from one voice to another. Maintain full control over emotion, timing and delivery. Documentation: https://elevenlabs.io/docs/api-reference/speech-to-speech/stream
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/elevenlabs_client/endpoints/speech_to_speech.rb', line 74 def convert_stream(voice_id, audio_file, filename, **, &block) endpoint = "/v1/speech-to-speech/#{voice_id}/stream" # Build query parameters query_params = {} query_params[:enable_logging] = [:enable_logging] unless [:enable_logging].nil? query_params[:optimize_streaming_latency] = [:optimize_streaming_latency] if [:optimize_streaming_latency] query_params[:output_format] = [:output_format] if [:output_format] # Add query parameters to endpoint if any exist if query_params.any? query_string = query_params.map { |k, v| "#{k}=#{v}" }.join("&") endpoint += "?#{query_string}" end # Build multipart payload payload = { audio: @client.file_part(audio_file, filename) } # Add optional form parameters payload[:model_id] = [:model_id] if [:model_id] payload[:voice_settings] = [:voice_settings] if [:voice_settings] payload[:seed] = [:seed] if [:seed] payload[:remove_background_noise] = [:remove_background_noise] unless [:remove_background_noise].nil? payload[:file_format] = [:file_format] if [: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..on_data = proc do |chunk, _| block.call(chunk) end end end @client.send(:handle_response, response) end |