Class: ElevenlabsClient::SpeechToText
- Inherits:
-
Object
- Object
- ElevenlabsClient::SpeechToText
- Defined in:
- lib/elevenlabs_client/endpoints/speech_to_text.rb
Instance Method Summary collapse
-
#create(model_id, **options) ⇒ Hash
(also: #transcribe)
POST /v1/speech-to-text Transcribe an audio or video file Documentation: https://elevenlabs.io/docs/api-reference/speech-to-text.
-
#delete_transcript(transcription_id) ⇒ Hash
(also: #delete_transcription, #remove_transcript)
DELETE /v1/speech-to-text/transcripts/:transcription_id Delete a previously generated transcript by its ID Documentation: https://elevenlabs.io/docs/api-reference/speech-to-text/delete-transcript.
-
#get_transcript(transcription_id) ⇒ Hash
(also: #get_transcription, #retrieve_transcript)
GET /v1/speech-to-text/transcripts/:transcription_id Retrieve a previously generated transcript by its ID Documentation: https://elevenlabs.io/docs/api-reference/speech-to-text/get-transcript.
-
#initialize(client) ⇒ SpeechToText
constructor
A new instance of SpeechToText.
Constructor Details
#initialize(client) ⇒ SpeechToText
Returns a new instance of SpeechToText.
5 6 7 |
# File 'lib/elevenlabs_client/endpoints/speech_to_text.rb', line 5 def initialize(client) @client = client end |
Instance Method Details
#create(model_id, **options) ⇒ Hash Also known as: transcribe
POST /v1/speech-to-text Transcribe an audio or video file Documentation: https://elevenlabs.io/docs/api-reference/speech-to-text
34 35 36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/elevenlabs_client/endpoints/speech_to_text.rb', line 34 def create(model_id, **) endpoint = "/v1/speech-to-text" # Build query parameters query_params = {} query_params[:enable_logging] = [:enable_logging] unless [:enable_logging].nil? # 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 = { model_id: model_id } # Add file or cloud storage URL (exactly one is required) if [:file] && [:filename] payload[:file] = @client.file_part([:file], [:filename]) elsif [:cloud_storage_url] payload[:cloud_storage_url] = [:cloud_storage_url] else raise ArgumentError, "Either :file with :filename or :cloud_storage_url must be provided" end # Add optional form parameters payload[:language_code] = [:language_code] if [:language_code] payload[:tag_audio_events] = [:tag_audio_events] unless [:tag_audio_events].nil? payload[:num_speakers] = [:num_speakers] if [:num_speakers] payload[:timestamps_granularity] = [:timestamps_granularity] if [:timestamps_granularity] payload[:diarize] = [:diarize] unless [:diarize].nil? payload[:diarization_threshold] = [:diarization_threshold] if [:diarization_threshold] payload[:additional_formats] = [:additional_formats] if [:additional_formats] payload[:file_format] = [:file_format] if [:file_format] payload[:webhook] = [:webhook] unless [:webhook].nil? payload[:webhook_id] = [:webhook_id] if [:webhook_id] payload[:temperature] = [:temperature] if [:temperature] payload[:seed] = [:seed] if [:seed] payload[:use_multi_channel] = [:use_multi_channel] unless [:use_multi_channel].nil? # Handle webhook_metadata (can be string or hash) if [:webhook_metadata] if [:webhook_metadata].is_a?(Hash) payload[:webhook_metadata] = [:webhook_metadata].to_json else payload[:webhook_metadata] = [:webhook_metadata] end end @client.post_multipart(endpoint, payload) end |
#delete_transcript(transcription_id) ⇒ Hash Also known as: delete_transcription, remove_transcript
DELETE /v1/speech-to-text/transcripts/:transcription_id Delete a previously generated transcript by its ID Documentation: https://elevenlabs.io/docs/api-reference/speech-to-text/delete-transcript
105 106 107 108 |
# File 'lib/elevenlabs_client/endpoints/speech_to_text.rb', line 105 def delete_transcript(transcription_id) endpoint = "/v1/speech-to-text/transcripts/#{transcription_id}" @client.delete(endpoint) end |
#get_transcript(transcription_id) ⇒ Hash Also known as: get_transcription, retrieve_transcript
GET /v1/speech-to-text/transcripts/:transcription_id Retrieve a previously generated transcript by its ID Documentation: https://elevenlabs.io/docs/api-reference/speech-to-text/get-transcript
94 95 96 97 |
# File 'lib/elevenlabs_client/endpoints/speech_to_text.rb', line 94 def get_transcript(transcription_id) endpoint = "/v1/speech-to-text/transcripts/#{transcription_id}" @client.get(endpoint) end |