Class: AssemblyAI::AsyncTranscriptsClient
- Inherits:
-
Object
- Object
- AssemblyAI::AsyncTranscriptsClient
- 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
Instance Method Summary collapse
-
#delete(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::Transcript
Remove the data from the transcript and mark it as deleted.
-
#get(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::Transcript
Get the transcript resource.
-
#get_paragraphs(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::ParagraphsResponse
Get the transcript split by paragraphs.
-
#get_redacted_audio(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::RedactedAudioResponse
Retrieve the redacted audio object containing the status and URL to the redacted audio.
-
#get_sentences(transcript_id:, request_options: nil) ⇒ AssemblyAI::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 use with a video player for subtitles and closed captions.
- #initialize(request_client:) ⇒ AssemblyAI::AsyncTranscriptsClient constructor
-
#list(limit: nil, status: nil, created_on: nil, before_id: nil, after_id: nil, throttled_only: nil, request_options: nil) ⇒ AssemblyAI::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.
-
#submit(audio_url:, language_code: nil, language_detection: nil, language_confidence_threshold: nil, speech_model: nil, punctuate: nil, format_text: nil, disfluencies: nil, multichannel: 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, custom_spelling: 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, request_options: nil) ⇒ AssemblyAI::Transcripts::Transcript
Create a transcript from a media file that is accessible via a URL.
-
#transcribe(audio_url:, language_code: nil, language_detection: nil, language_confidence_threshold: nil, speech_model: nil, punctuate: nil, format_text: nil, disfluencies: nil, multichannel: 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, custom_spelling: 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, 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) ⇒ AssemblyAI::Transcripts::WordSearchResponse
Search through the transcript for keywords.
Constructor Details
#initialize(request_client:) ⇒ AssemblyAI::AsyncTranscriptsClient
380 381 382 |
# File 'lib/assemblyai/transcripts/client.rb', line 380 def initialize(request_client:) @request_client = request_client end |
Instance Attribute Details
#request_client ⇒ AssemblyAI::AsyncRequestClient (readonly)
376 377 378 |
# File 'lib/assemblyai/transcripts/client.rb', line 376 def request_client @request_client end |
Instance Method Details
#delete(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::Transcript
Remove the data from the transcript and mark it as deleted.
608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/assemblyai/transcripts/client.rb', line 608 def delete(transcript_id:, request_options: nil) Async do 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 AssemblyAI::Transcripts::Transcript.from_json(json_object: response.body) end end |
#get(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::Transcript
Get the transcript resource. The transcript is ready when the “status” is
"completed".
584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/assemblyai/transcripts/client.rb', line 584 def get(transcript_id:, request_options: nil) Async do 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 AssemblyAI::Transcripts::Transcript.from_json(json_object: response.body) end end |
#get_paragraphs(transcript_id:, request_options: nil) ⇒ AssemblyAI::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.
684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/assemblyai/transcripts/client.rb', line 684 def get_paragraphs(transcript_id:, request_options: nil) Async do 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 AssemblyAI::Transcripts::ParagraphsResponse.from_json(json_object: response.body) end end |
#get_redacted_audio(transcript_id:, request_options: nil) ⇒ AssemblyAI::Transcripts::RedactedAudioResponse
Retrieve the redacted audio object containing the status and URL to the redacted
audio.
729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/assemblyai/transcripts/client.rb', line 729 def get_redacted_audio(transcript_id:, request_options: nil) Async do 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 AssemblyAI::Transcripts::RedactedAudioResponse.from_json(json_object: response.body) end end |
#get_sentences(transcript_id:, request_options: nil) ⇒ AssemblyAI::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.
658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/assemblyai/transcripts/client.rb', line 658 def get_sentences(transcript_id:, request_options: nil) Async do 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 AssemblyAI::Transcripts::SentencesResponse.from_json(json_object: response.body) end end |
#get_subtitles(transcript_id:, subtitle_format:, chars_per_caption: nil, request_options: nil) ⇒ String
Export your transcript in SRT or VTT format to use with a video player for
subtitles and closed captions.
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/assemblyai/transcripts/client.rb', line 628 def get_subtitles(transcript_id:, subtitle_format:, chars_per_caption: nil, request_options: nil) Async do 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": }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript/#{transcript_id}/#{subtitle_format}" end response.body end end |
#list(limit: nil, status: nil, created_on: nil, before_id: nil, after_id: nil, throttled_only: nil, request_options: nil) ⇒ AssemblyAI::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.
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/assemblyai/transcripts/client.rb', line 403 def list(limit: nil, status: nil, created_on: nil, before_id: nil, after_id: nil, throttled_only: nil, request_options: nil) Async do 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 AssemblyAI::Transcripts::TranscriptList.from_json(json_object: response.body) end end |
#list_by_url(url: nil, request_options: nil) ⇒ Transcripts::TranscriptList
Retrieve a list of transcripts you created
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/assemblyai/transcripts/list_by_url_client.rb', line 46 def list_by_url(url: nil, request_options: nil) Async do 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 end |
#submit(audio_url:, language_code: nil, language_detection: nil, language_confidence_threshold: nil, speech_model: nil, punctuate: nil, format_text: nil, disfluencies: nil, multichannel: 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, custom_spelling: 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, request_options: nil) ⇒ AssemblyAI::Transcripts::Transcript
Create a transcript from a media file that is accessible via a URL.
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/assemblyai/transcripts/client.rb', line 516 def submit(audio_url:, language_code: nil, language_detection: nil, language_confidence_threshold: nil, speech_model: nil, punctuate: nil, format_text: nil, disfluencies: nil, multichannel: 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, custom_spelling: 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, request_options: nil) Async do 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 || {}), language_code: language_code, language_detection: language_detection, language_confidence_threshold: language_confidence_threshold, speech_model: speech_model, punctuate: punctuate, format_text: format_text, disfluencies: disfluencies, multichannel: multichannel, 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, custom_spelling: custom_spelling, 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, audio_url: audio_url }.compact req.url "#{@request_client.get_url(request_options: )}/v2/transcript" end AssemblyAI::Transcripts::Transcript.from_json(json_object: response.body) end end |
#transcribe(audio_url:, language_code: nil, language_detection: nil, language_confidence_threshold: nil, speech_model: nil, punctuate: nil, format_text: nil, disfluencies: nil, multichannel: 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, custom_spelling: 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, 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.
228 229 230 231 232 233 234 235 |
# File 'lib/assemblyai/transcripts/polling_client.rb', line 228 def transcribe(audio_url:, language_code: nil, language_detection: nil, language_confidence_threshold: nil, speech_model: nil, punctuate: nil, format_text: nil, disfluencies: nil, multichannel: 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, custom_spelling: 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, request_options: nil, polling_options: Transcripts::PollingOptions.new) Async do 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, language_confidence_threshold: language_confidence_threshold, custom_spelling: custom_spelling, disfluencies: disfluencies, multichannel: multichannel, 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, request_options: ) wait_until_ready(transcript_id: transcript.id, polling_options: ).wait end 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”.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/assemblyai/transcripts/polling_client.rb', line 242 def wait_until_ready(transcript_id:, polling_options: Transcripts::PollingOptions.new) Async do 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 end |
#word_search(transcript_id:, words: nil, request_options: nil) ⇒ AssemblyAI::Transcripts::WordSearchResponse
Search through the transcript for keywords. You can search for individual words,
numbers, or phrases containing up to five words or numbers.
703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/assemblyai/transcripts/client.rb', line 703 def word_search(transcript_id:, words: nil, request_options: nil) Async do 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 AssemblyAI::Transcripts::WordSearchResponse.from_json(json_object: response.body) end end |