Skip to content

Commit

Permalink
🌿 Bring new Fern changes to fernignored files
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo committed Feb 27, 2024
1 parent 3c5b196 commit 59e5daf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ You can configure the polling interval and polling timeout using these options:
transcript = client.transcripts.transcribe(
audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a",
AssemblyAI::Transcripts::PollingInterval.new(
// How frequently the transcript is polled in ms. Defaults to 3000.
# How frequently the transcript is polled in ms. Defaults to 3000.
interval: 1000,
// How long to wait in ms until the "Polling timeout" error is thrown. Defaults to infinite (-1).
# How long to wait in ms until the "Polling timeout" error is thrown. Defaults to infinite (-1).
timeout: 5000,
)
);
Expand Down
36 changes: 19 additions & 17 deletions lib/assemblyai/transcripts/polling_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class TranscriptsClient
# 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.
#
# @param language_code [TRANSCRIPT_LANGUAGE_CODE]
# @param speech_model [Transcripts::SpeechModel]
# @param language_code [Transcripts::TranscriptLanguageCode]
# @param punctuate [Boolean] Enable Automatic Punctuation, can be true or false
# @param format_text [Boolean] Enable Text Formatting, can be true or false
# @param dual_channel [Boolean] Enable [Dual Channel](https://www.assemblyai.com/docs/models/speech-recognition#dual-channel-transcription) transcription, can be true or false.
Expand All @@ -37,13 +38,13 @@ class TranscriptsClient
# @param audio_start_from [Integer] The point in time, in milliseconds, to begin transcribing in your media file
# @param audio_end_at [Integer] The point in time, in milliseconds, to stop transcribing in your media file
# @param word_boost [Array<String>] The list of custom vocabulary to boost transcription probability for
# @param boost_param [TRANSCRIPT_BOOST_PARAM] The word boost parameter value
# @param boost_param [Transcripts::TranscriptBoostParam] The word boost parameter value
# @param filter_profanity [Boolean] Filter profanity from the transcribed text, can be true or false
# @param redact_pii [Boolean] Redact PII from the transcribed text using the Redact PII model, can be true or false
# @param redact_pii_audio [Boolean] Generate a copy of the original media file with spoken PII "beeped" out, can be true or false. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_audio_quality [REDACT_PII_AUDIO_QUALITY] Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_policies [Array<Transcripts::PII_POLICY>] The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_sub [SUBSTITUTION_POLICY]
# @param redact_pii_audio_quality [Transcripts::RedactPiiAudioQuality] Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_policies [Array<Transcripts::PiiPolicy>] The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_sub [Transcripts::SubstitutionPolicy]
# @param speaker_labels [Boolean] Enable [Speaker diarization](https://www.assemblyai.com/docs/models/speaker-diarization), can be true or false
# @param speakers_expected [Integer] Tells the speaker label model how many speakers it should attempt to identify, up to 10. See [Speaker diarization](https://www.assemblyai.com/docs/models/speaker-diarization) for more details.
# @param content_safety [Boolean] Enable [Content Moderation](https://www.assemblyai.com/docs/models/content-moderation), can be true or false
Expand All @@ -60,8 +61,8 @@ class TranscriptsClient
# @param speech_threshold [Float] Reject audio files that contain less than this fraction of speech.
# Valid values are in the range [0, 1] inclusive.
# @param summarization [Boolean] Enable [Summarization](https://www.assemblyai.com/docs/models/summarization), can be true or false
# @param summary_model [SUMMARY_MODEL] The model to summarize the transcript
# @param summary_type [SUMMARY_TYPE] The type of summary
# @param summary_model [Transcripts::SummaryModel] The model to summarize the transcript
# @param summary_type [Transcripts::SummaryType] The type of summary
# @param custom_topics [Boolean] Whether custom topics is enabled, either true or false
# @param topics [Array<String>] The list of custom topics provided, if custom topics is enabled
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
Expand All @@ -81,7 +82,7 @@ def poll_transcript(transcript_id:, polling_options:)
timeout_in_seconds = polling_options.timeout / 1000 if polling_options.timeout.positive?
loop do
transcript = get(transcript_id: transcript_id)
if transcript.status == :completed || transcript.status == :error
if transcript.status == Transcripts::TranscriptStatus::COMPLETED || transcript.status == Transcripts::TranscriptStatus::ERROR
return transcript
elsif polling_options.timeout.positive? && Time.now - start_time > timeout_in_seconds
raise StandardError, "Polling timeout"
Expand All @@ -99,7 +100,8 @@ class AsyncTranscriptsClient
# 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.
#
# @param language_code [TRANSCRIPT_LANGUAGE_CODE]
# @param speech_model [Transcripts::SpeechModel]
# @param language_code [Transcripts::TranscriptLanguageCode]
# @param punctuate [Boolean] Enable Automatic Punctuation, can be true or false
# @param format_text [Boolean] Enable Text Formatting, can be true or false
# @param dual_channel [Boolean] Enable [Dual Channel](https://www.assemblyai.com/docs/models/speech-recognition#dual-channel-transcription) transcription, can be true or false.
Expand All @@ -110,13 +112,13 @@ class AsyncTranscriptsClient
# @param audio_start_from [Integer] The point in time, in milliseconds, to begin transcribing in your media file
# @param audio_end_at [Integer] The point in time, in milliseconds, to stop transcribing in your media file
# @param word_boost [Array<String>] The list of custom vocabulary to boost transcription probability for
# @param boost_param [TRANSCRIPT_BOOST_PARAM] The word boost parameter value
# @param boost_param [Transcripts::TranscriptBoostParam] The word boost parameter value
# @param filter_profanity [Boolean] Filter profanity from the transcribed text, can be true or false
# @param redact_pii [Boolean] Redact PII from the transcribed text using the Redact PII model, can be true or false
# @param redact_pii_audio [Boolean] Generate a copy of the original media file with spoken PII "beeped" out, can be true or false. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_audio_quality [REDACT_PII_AUDIO_QUALITY] Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_policies [Array<Transcripts::PII_POLICY>] The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_sub [SUBSTITUTION_POLICY]
# @param redact_pii_audio_quality [Transcripts::RedactPiiAudioQuality] Controls the filetype of the audio created by redact_pii_audio. Currently supports mp3 (default) and wav. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_policies [Array<Transcripts::PiiPolicy>] The list of PII Redaction policies to enable. See [PII redaction](https://www.assemblyai.com/docs/models/pii-redaction) for more details.
# @param redact_pii_sub [Transcripts::SubstitutionPolicy]
# @param speaker_labels [Boolean] Enable [Speaker diarization](https://www.assemblyai.com/docs/models/speaker-diarization), can be true or false
# @param speakers_expected [Integer] Tells the speaker label model how many speakers it should attempt to identify, up to 10. See [Speaker diarization](https://www.assemblyai.com/docs/models/speaker-diarization) for more details.
# @param content_safety [Boolean] Enable [Content Moderation](https://www.assemblyai.com/docs/models/content-moderation), can be true or false
Expand All @@ -133,14 +135,14 @@ class AsyncTranscriptsClient
# @param speech_threshold [Float] Reject audio files that contain less than this fraction of speech.
# Valid values are in the range [0, 1] inclusive.
# @param summarization [Boolean] Enable [Summarization](https://www.assemblyai.com/docs/models/summarization), can be true or false
# @param summary_model [SUMMARY_MODEL] The model to summarize the transcript
# @param summary_type [SUMMARY_TYPE] The type of summary
# @param summary_model [Transcripts::SummaryModel] The model to summarize the transcript
# @param summary_type [Transcripts::SummaryType] The type of summary
# @param custom_topics [Boolean] Whether custom topics is enabled, either true or false
# @param topics [Array<String>] The list of custom topics provided, if custom topics is enabled
# @param additional_properties [OpenStruct] Additional properties unmapped to the current class definition
# @param audio_url [String] The URL of the audio or video file to transcribe.
# @param request_options [RequestOptions]
# @param polling_options [PollingOptions] Configuration options for polling requests.
# @param polling_options [Transcripts::PollingOptions] Configuration options for polling requests.
# @return [Transcripts::Transcript]
def transcribe(audio_url:, 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)
Expand All @@ -157,7 +159,7 @@ def poll_transcript(transcript_id:, polling_options:)
timeout_in_seconds = polling_options.timeout / 1000 if polling_options.timeout.positive?
loop do
transcript = get(transcript_id: transcript_id).wait
if transcript.status == :completed || transcript.status == :error
if transcript.status == Transcripts::TranscriptStatus::COMPLETED || transcript.status == Transcripts::TranscriptStatus::ERROR
break transcript
elsif polling_options.timeout.positive? && Time.now - start_time > timeout_in_seconds
raise StandardError, "Polling timeout"
Expand Down
5 changes: 3 additions & 2 deletions test/test_assemblyai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ class TestAssemblyAI < Minitest::Test
def test_polling
client = AssemblyAI::Client.new(api_key: "YOUR_API_KEY")
transcript = client.transcripts.transcribe(audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a")
assert transcript.status == :completed
assert transcript.status == AssemblyAI::Transcripts::TranscriptStatus::COMPLETED

client = AssemblyAI::AsyncClient.new(api_key: "YOUR_API_KEY")
Sync do
transcript_task = client.transcripts.transcribe(audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a")
assert transcript_task.is_a? Async::Task
transcript = transcript_task.wait
assert transcript.status == :completed
puts transcript.status
assert transcript.status == AssemblyAI::Transcripts::TranscriptStatus::COMPLETED
end
end

Expand Down

0 comments on commit 59e5daf

Please sign in to comment.