Skip to content

Commit

Permalink
Update README.md add client.transcripts.list_by_url
Browse files Browse the repository at this point in the history
  • Loading branch information
Swimburger committed Feb 28, 2024
1 parent 3c5b196 commit 279d248
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 21 deletions.
1 change: 1 addition & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ test/
<!-- Allow for the polling client -->
lib/assemblyai.rb
lib/assemblyai/transcripts/polling_client.rb
lib/assemblyai/transcripts/listing_client.rb
lib/assemblyai/transcripts/types/polling_options.rb

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/tmp/
*.gem
.env
/.idea
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,40 @@ gem install assemblyai
Import the AssemblyAI package and create an AssemblyAI object with your API key:

```ruby
require "assemblyai"
require 'assemblyai'

client = AssemblyAI::Client.new(api_key: "YOUR_API_KEY")
client = AssemblyAI::Client.new(api_key: 'YOUR_API_KEY')
```
You can now use the `client` object to interact with the AssemblyAI API.

## Create a transcript

```ruby
transcript = client.transcripts.transcribe(
audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a",
);
audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a',
)
```

`transcribe` queues a transcription job and polls it until the `status` is `completed` or `error`.
You can configure the polling interval and polling timeout using these options:

```ruby
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.
audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a',
polling_options: AssemblyAI::Transcripts::PollingOptions.new(
# 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).
timeout: 5000,
# How long to wait in ms until the 'Polling timeout' error is thrown. Defaults to infinite (-1).
timeout: 5000
)
);
)
```

If you don't want to wait until the transcript is ready, you can use `submit`:

```ruby
# Transcribe file at remote URL
transcript = client.transcripts.submit(
audio_url: "https://storage.googleapis.com/aai-web-samples/espn-bears.m4a"
audio_url: 'https://storage.googleapis.com/aai-web-samples/espn-bears.m4a'
)
```

Expand All @@ -92,6 +91,17 @@ This will return a page of transcripts you created.
page = client.transcripts.list
```

You can also paginate over all pages.

```ruby
next_page_url = nil
loop do
page = client.transcripts.list_by_url(url: next_page_url)
next_page_url = page.page_details.next_url
break if next_page_url.nil?
end
```

## Delete a transcript

```ruby
Expand All @@ -106,10 +116,10 @@ Custom Summary:

```ruby
response = client.lemur.summary(
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
answer_format: "one sentence",
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
answer_format: 'one sentence',
context: {
"speakers": ["Alex", "Bob"]
'speakers': ['Alex', 'Bob']
}
)
```
Expand All @@ -118,11 +128,11 @@ Question & Answer:

```ruby
response = client.lemur.question_answer(
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
questions: [
{
question: "What are they discussing?",
answer_format: "text"
question: 'What are they discussing?',
answer_format: 'text'
}
]
)
Expand All @@ -132,15 +142,15 @@ Action Items:

```ruby
response = client.lemur.action_items(
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"]
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927']
)
```

Custom Task:

```ruby
response = client.lemur.task(
transcript_ids: ["0d295578-8c75-421a-885a-2c487f188927"],
prompt: "Write a haiku about this conversation."
transcript_ids: ['0d295578-8c75-421a-885a-2c487f188927'],
prompt: 'Write a haiku about this conversation.'
)
```
63 changes: 63 additions & 0 deletions lib/assemblyai/transcripts/list_by_url_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# frozen_string_literal: true

require_relative "../../requests"
require_relative "types/transcript_status"
require_relative "types/transcript_list"
require_relative "types/transcript_language_code"
require_relative "types/transcript_boost_param"
require_relative "types/redact_pii_audio_quality"
require_relative "types/pii_policy"
require_relative "types/substitution_policy"
require_relative "types/transcript_custom_spelling"
require_relative "types/summary_model"
require_relative "types/summary_type"
require_relative "types/transcript"
require_relative "types/subtitle_format"
require_relative "types/sentences_response"
require_relative "types/paragraphs_response"
require_relative "types/word_search_response"
require_relative "types/redacted_audio_response"
require_relative "types/polling_options"
require "async"

module AssemblyAI
# Retrieve a list of transcripts you created
#
# @param url [String] The URL to retrieve the transcript list from
# @param request_options [RequestOptions]
# @return [Transcripts::TranscriptList]
def list_by_url(url: nil, request_options: nil)
if url.nil?
url = "/v2/transcript"
end
response = @request_client.conn.get(url) do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
end
Transcripts::TranscriptList.from_json(json_object: response.body)
end

# :nodoc:
class AsyncTranscriptsClient

# Retrieve a list of transcripts you created
#
# @param url [String] The URL to retrieve the transcript list from
# @param request_options [RequestOptions]
# @return [Transcripts::TranscriptList]
def list_by_url(url: nil, request_options: nil)
Async do
if url.nil?
url = "/v2/transcript"
end
response = @request_client.conn.get(url) do |req|
req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
end
Transcripts::TranscriptList.from_json(json_object: response.body)
end
end
end
end

0 comments on commit 279d248

Please sign in to comment.