Class: AssemblyAI::TranscriptsClient
- Inherits:
-
Object
- Object
- AssemblyAI::TranscriptsClient
- Defined in:
- lib/assemblyai/transcripts/polling_client.rb,
lib/assemblyai/transcripts/client.rb,
lib/assemblyai/transcripts/list_by_url_client.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
-
#delete(transcript_id:, request_options: nil) ⇒ Transcripts::Transcript
Delete the transcript.
-
#get(transcript_id:, request_options: nil) ⇒ Transcripts::Transcript
Get the transcript resource.
-
#get_paragraphs(transcript_id:, request_options: nil) ⇒ Transcripts::ParagraphsResponse
Get the transcript split by paragraphs.
-
#get_redacted_audio(transcript_id:, request_options: nil) ⇒ Transcripts::RedactedAudioResponse
Retrieve the redacted audio object containing the status and URL to the redacted audio.
-
#get_sentences(transcript_id:, request_options: nil) ⇒ Transcripts::SentencesResponse
Get the transcript split by sentences.
-
#get_subtitles(transcript_id:, subtitle_format:, chars_per_caption: nil, request_options: nil) ⇒ String
Export your transcript in SRT or VTT format, to be plugged into a video player for subtitles and closed captions.
- #initialize(request_client:) ⇒ TranscriptsClient constructor
-
#list(limit: nil, status: nil, created_on: nil, before_id: nil, after_id: nil, throttled_only: nil, request_options: nil) ⇒ Transcripts::TranscriptList
Retrieve a list of transcripts you created.
-
#list_by_url(url: nil, request_options: nil) ⇒ Transcripts::TranscriptList
Retrieve a list of transcripts you created, this is used for pagination to easily retrieve the next page of transcripts.
-
#submit(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil) ⇒ Transcripts::Transcript
Create a transcript from an audio or video file that is accessible via a URL.
-
#transcribe(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new) ⇒ Transcripts::Transcript
Create a transcript from an audio or video file that is accessible via a URL.
-
#wait_until_ready(transcript_id:, polling_options: Transcripts::PollingOptions.new) ⇒ Transcripts::Transcript
Wait until the transcript is ready.
-
#word_search(transcript_id:, words: nil, request_options: nil) ⇒ Transcripts::WordSearchResponse
Search through the transcript for a specific set of keywords.
Constructor Details
#initialize(request_client:) ⇒ TranscriptsClient
29 30 31 32 |
# File 'lib/assemblyai/transcripts/client.rb', line 29 def initialize(request_client:) # @type [RequestClient] @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ Object (readonly)
Returns the value of attribute request_client.
25 26 27 |
# File 'lib/assemblyai/transcripts/client.rb', line 25 def request_client @request_client end |
Instance Method Details
#delete(transcript_id:, request_options: nil) ⇒ Transcripts::Transcript
Delete the transcript
182 183 184 185 186 187 188 189 190 |
# File 'lib/assemblyai/transcripts/client.rb', line 182 def delete(transcript_id:, request_options: nil) response = @request_client.conn.delete do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}" end Transcripts::Transcript.from_json(json_object: response.body) end |
#get(transcript_id:, request_options: nil) ⇒ Transcripts::Transcript
Get the transcript resource. The transcript is ready when the “status” is “completed”.
167 168 169 170 171 172 173 174 175 |
# File 'lib/assemblyai/transcripts/client.rb', line 167 def get(transcript_id:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}" end Transcripts::Transcript.from_json(json_object: response.body) end |
#get_paragraphs(transcript_id:, request_options: nil) ⇒ Transcripts::ParagraphsResponse
Get the transcript split by paragraphs. The API will attempt to semantically segment your transcript into paragraphs to create more reader-friendly transcripts.
233 234 235 236 237 238 239 240 241 |
# File 'lib/assemblyai/transcripts/client.rb', line 233 def get_paragraphs(transcript_id:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}/paragraphs" end Transcripts::ParagraphsResponse.from_json(json_object: response.body) end |
#get_redacted_audio(transcript_id:, request_options: nil) ⇒ Transcripts::RedactedAudioResponse
Retrieve the redacted audio object containing the status and URL to the redacted audio.
265 266 267 268 269 270 271 272 273 |
# File 'lib/assemblyai/transcripts/client.rb', line 265 def get_redacted_audio(transcript_id:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}/redacted-audio" end Transcripts::RedactedAudioResponse.from_json(json_object: response.body) end |
#get_sentences(transcript_id:, request_options: nil) ⇒ Transcripts::SentencesResponse
Get the transcript split by sentences. The API will attempt to semantically segment the transcript into sentences to create more reader-friendly transcripts.
218 219 220 221 222 223 224 225 226 |
# File 'lib/assemblyai/transcripts/client.rb', line 218 def get_sentences(transcript_id:, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}/sentences" end Transcripts::SentencesResponse.from_json(json_object: response.body) end |
#get_subtitles(transcript_id:, subtitle_format:, chars_per_caption: nil, request_options: nil) ⇒ String
Export your transcript in SRT or VTT format, to be plugged into a video player for subtitles and closed captions.
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/assemblyai/transcripts/client.rb', line 199 def get_subtitles(transcript_id:, subtitle_format:, chars_per_caption: nil, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "chars_per_caption": chars_per_caption }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}/#{subtitle_format}" end response.body end |
#list(limit: nil, status: nil, created_on: nil, before_id: nil, after_id: nil, throttled_only: nil, request_options: nil) ⇒ Transcripts::TranscriptList
Retrieve a list of transcripts you created. Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/assemblyai/transcripts/client.rb', line 45 def list(limit: nil, status: nil, created_on: nil, before_id: nil, after_id: nil, throttled_only: nil, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "limit": limit, "status": status, "created_on": created_on, "before_id": before_id, "after_id": after_id, "throttled_only": throttled_only }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript" end Transcripts::TranscriptList.from_json(json_object: response.body) end |
#list_by_url(url: nil, request_options: nil) ⇒ Transcripts::TranscriptList
Retrieve a list of transcripts you created, this is used for pagination to easily retrieve the next page of transcripts
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/assemblyai/transcripts/list_by_url_client.rb', line 20 def list_by_url(url: nil, request_options: nil) url = "#{@request_client.get_url(request_options: )}/v2/transcript" if url.nil? response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.url url end Transcripts::TranscriptList.from_json(json_object: response.body) end |
#submit(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil) ⇒ Transcripts::Transcript
Create a transcript from an audio or video file that is accessible via a URL.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/assemblyai/transcripts/client.rb', line 110 def submit(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil) response = @request_client.conn.post do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), speech_model: speech_model, language_code: language_code, punctuate: punctuate, format_text: format_text, dual_channel: dual_channel, webhook_url: webhook_url, webhook_auth_header_name: webhook_auth_header_name, webhook_auth_header_value: webhook_auth_header_value, auto_highlights: auto_highlights, audio_start_from: audio_start_from, audio_end_at: audio_end_at, word_boost: word_boost, boost_param: boost_param, filter_profanity: filter_profanity, redact_pii: redact_pii, redact_pii_audio: redact_pii_audio, redact_pii_audio_quality: redact_pii_audio_quality, redact_pii_policies: redact_pii_policies, redact_pii_sub: redact_pii_sub, speaker_labels: speaker_labels, speakers_expected: speakers_expected, content_safety: content_safety, content_safety_confidence: content_safety_confidence, iab_categories: iab_categories, language_detection: language_detection, custom_spelling: custom_spelling, disfluencies: disfluencies, sentiment_analysis: sentiment_analysis, auto_chapters: auto_chapters, entity_detection: entity_detection, speech_threshold: speech_threshold, summarization: summarization, summary_model: summary_model, summary_type: summary_type, custom_topics: custom_topics, topics: topics, additional_properties: additional_properties, audio_url: audio_url }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript" end Transcripts::Transcript.from_json(json_object: response.body) end |
#transcribe(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new) ⇒ Transcripts::Transcript
Create a transcript from an audio or video file that is accessible via a URL. .transcribe polls for completion of the transcription, while the .submit function does not.
73 74 75 76 77 78 |
# File 'lib/assemblyai/transcripts/polling_client.rb', line 73 def transcribe(audio_url:, speech_model: nil, language_code: nil, punctuate: nil, format_text: nil, dual_channel: nil, webhook_url: nil, webhook_auth_header_name: nil, webhook_auth_header_value: nil, auto_highlights: nil, audio_start_from: nil, audio_end_at: nil, word_boost: nil, boost_param: nil, filter_profanity: nil, redact_pii: nil, redact_pii_audio: nil, redact_pii_audio_quality: nil, redact_pii_policies: nil, redact_pii_sub: nil, speaker_labels: nil, speakers_expected: nil, content_safety: nil, content_safety_confidence: nil, iab_categories: nil, language_detection: nil, custom_spelling: nil, disfluencies: nil, sentiment_analysis: nil, auto_chapters: nil, entity_detection: nil, speech_threshold: nil, summarization: nil, summary_model: nil, summary_type: nil, custom_topics: nil, topics: nil, additional_properties: nil, request_options: nil, polling_options: Transcripts::PollingOptions.new) transcript = submit(audio_url: audio_url, speech_model: speech_model, language_code: language_code, punctuate: punctuate, format_text: format_text, dual_channel: dual_channel, webhook_url: webhook_url, webhook_auth_header_name: webhook_auth_header_name, webhook_auth_header_value: webhook_auth_header_value, auto_highlights: auto_highlights, audio_start_from: audio_start_from, audio_end_at: audio_end_at, word_boost: word_boost, boost_param: boost_param, filter_profanity: filter_profanity, redact_pii: redact_pii, redact_pii_audio: redact_pii_audio, redact_pii_audio_quality: redact_pii_audio_quality, redact_pii_policies: redact_pii_policies, redact_pii_sub: redact_pii_sub, speaker_labels: speaker_labels, speakers_expected: speakers_expected, content_safety: content_safety, content_safety_confidence: content_safety_confidence, iab_categories: iab_categories, language_detection: language_detection, custom_spelling: custom_spelling, disfluencies: disfluencies, sentiment_analysis: sentiment_analysis, auto_chapters: auto_chapters, entity_detection: entity_detection, speech_threshold: speech_threshold, summarization: summarization, summary_model: summary_model, summary_type: summary_type, custom_topics: custom_topics, topics: topics, additional_properties: additional_properties, request_options: ) wait_until_ready(transcript_id: transcript.id, polling_options: ) end |
#wait_until_ready(transcript_id:, polling_options: Transcripts::PollingOptions.new) ⇒ Transcripts::Transcript
Wait until the transcript is ready. The transcript is ready when the “status” is “completed”.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/assemblyai/transcripts/polling_client.rb', line 85 def wait_until_ready(transcript_id:, polling_options: Transcripts::PollingOptions.new) start_time = Time.now timeout_in_seconds = .timeout / 1000 if .timeout.positive? loop do transcript = get(transcript_id: transcript_id) if transcript.status == Transcripts::TranscriptStatus::COMPLETED || transcript.status == Transcripts::TranscriptStatus::ERROR return transcript elsif .timeout.positive? && Time.now - start_time > timeout_in_seconds raise StandardError, "Polling timeout" end sleep .interval / 1000 end end |
#word_search(transcript_id:, words: nil, request_options: nil) ⇒ Transcripts::WordSearchResponse
Search through the transcript for a specific set of keywords. You can search for individual words, numbers, or phrases containing up to five words or numbers.
249 250 251 252 253 254 255 256 257 258 |
# File 'lib/assemblyai/transcripts/client.rb', line 249 def word_search(transcript_id:, words: nil, request_options: nil) response = @request_client.conn.get do |req| req..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? req.headers["Authorization"] = .api_key unless &.api_key.nil? req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.additional_query_parameters || {}), "words": words }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}/word-search" end Transcripts::WordSearchResponse.from_json(json_object: response.body) end |