diff --git a/Gemfile.lock b/Gemfile.lock index 78f46b4..7defe75 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - podcast_api (3.1.0) + podcast_api (3.2.0) httparty (>= 0.24.1, < 0.25) GEM diff --git a/README.md b/README.md index 490d1b3..2c918dc 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,9 @@ [![Ruby CI](https://github.com/ListenNotes/podcast-api-ruby/actions/workflows/ruby.yml/badge.svg)](https://github.com/ListenNotes/podcast-api-ruby/actions/workflows/ruby.yml) [![Gem](https://img.shields.io/gem/v/podcast_api)](https://rubygems.org/gems/podcast_api) -The Podcast API Ruby library provides convenient access to the [Listen Notes Podcast API](https://www.listennotes.com/podcast-api/) from -applications written in Ruby. +Search podcasts and episodes, generate speaker-labeled transcripts on demand, and get podcast audience insights with the official Ruby SDK for the [Listen Notes Podcast API](https://www.listennotes.com/api/). -Simple and no-nonsense podcast search & directory API. Search the meta data of all podcasts and episodes by people, places, or topics. It's the same API that powers the [best podcast search engine Listen Notes](https://www.listennotes.com/). +You can also discover podcasts in ChatGPT, Claude, or another compatible AI assistant without writing code. [Connect the official Podcast MCP](https://www.listennotes.com/api/mcp/). If you have any questions, please contact [hello@listennotes.com](hello@listennotes.com?subject=Questions+about+the+Ruby+SDK+of+Listen+API) @@ -57,9 +56,28 @@ If you have any questions, please contact [hello@listennotes.com](hello@listenno - [`add_playlist_item`](#add_playlist_item) — `POST /playlists/{id}/items` - [`delete_playlist_item`](#delete_playlist_item) — `DELETE /playlists/{id}/items/{item_id}` - [`update_playlist_item_notes`](#update_playlist_item_notes) — `PUT /playlists/{id}/items/{item_id}` +- [`estimate_episode_transcription`](#estimate_episode_transcription) — `GET /episodes/{id}/transcript/estimate` +- [`transcribe_episode`](#transcribe_episode) — `POST /episodes/{id}/transcript` +- [`get_episode_transcript`](#get_episode_transcript) — `GET /episodes/{id}/transcript` +- [`list_transcripts`](#list_transcripts) — `GET /transcripts` +## On-demand podcast transcription + +Transcription methods are available in version 3.2.0. Use the [mock API](https://www.listennotes.help/article/48-how-to-test-the-podcast-api-without-an-api-key) to try the examples with fixed responses and no API key. + +| Method | What it does | +| --- | --- | +| [`estimate_episode_transcription`](#estimate_episode_transcription) | Estimate cost and check your remaining transcription quota. | +| [`transcribe_episode`](#transcribe_episode) | Queue a transcription for a podcast episode. | +| [`get_episode_transcript`](#get_episode_transcript) | Poll for job status and get fresh signed download URLs. | +| [`list_transcripts`](#list_transcripts) | List completed transcripts and paginate with `next_cursor`. | + +**Can I get speaker-labeled podcast transcripts?** Yes. When multiple voices are detected, TXT, SRT, and VTT include speaker labels. Word-level JSON includes speaker IDs when available and timestamps in milliseconds. Signed links expire after 15 minutes. Poll again for fresh links. + +**Can I request a live transcription?** Enable transcription and set up billing in your API dashboard, then use a server-side API key. Check the estimate first because live requests can incur transcription fees. [Transcription settings](https://www.listennotes.com/api/dashboard/#transcription) · [Pricing](https://www.listennotes.com/api/pricing/#on-demand-transcription) + ## Installation Install [the official Ruby Gem](https://rubygems.org/gems/podcast_api) of the Listen Notes Podcast API: @@ -401,7 +419,11 @@ Fetch detailed meta data for an episode by id `GET /episodes/{id}` -Fetch detailed meta data for a specific episode. +Fetch detailed metadata for a specific episode. + +Existing episode transcripts are already available on Listen Notes and include transcripts supplied by podcast producers. About 12% of new episodes and over 3% of all episodes have an existing transcript. Retrieve one with `show_transcript=1` on PRO and ENTERPRISE. + +If an episode has no transcript, use `POST /episodes/{id}/transcript` to request on-demand transcription on any plan. ```ruby require "podcast_api" @@ -885,4 +907,124 @@ puts response.parsed_response [Full API documentation](https://www.listennotes.com/api/docs/#put-api-v2-playlists-id-items-item_id) +### estimate_episode_transcription + +Estimate episode transcription cost + +`GET /episodes/{id}/transcript/estimate` + +Get an informational estimate using episode duration metadata, your remaining quota, and your account's per-minute overage rate. This does not start transcription or reserve quota. + +`transcription_quota_this_cycle` shows the included and remaining minutes. `billing_this_transcription.amount_cents` is the estimated fee for minutes beyond the remaining quota. It is 0 when the estimate fits within the quota. + +The final fee uses the audio duration measured by the model, the quota available when transcription completes, and the per-minute rate saved when the request is accepted. + +If duration metadata is unavailable, `estimate`, `billing_this_transcription.billable_minutes`, and `billing_this_transcription.amount_cents` are null. You can request an estimate before enabling Transcription or adding a payment method. Normal API request accounting applies. + +```ruby +require "podcast_api" + +client = PodcastApi::Client.new(api_key: ENV["LISTEN_API_KEY"]) +response = client.estimate_episode_transcription(**{ + 'id' => 'dc09fd798802477b8dba0ca1e10134fa' +}) +puts response.parsed_response +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-episodes-id-transcript-estimate) + +### transcribe_episode + +Request episode transcription + +`POST /episodes/{id}/transcript` + +Generate speaker-labeled transcripts for a podcast episode on demand. The request runs asynchronously. Ensure Transcription is enabled and a payment method is added in the [API dashboard](https://www.listennotes.com/api/dashboard/#transcription). Eligible paid accounts may use their existing invoicing arrangement. + +**On-demand transcription can incur fees. This example uses the mock API. Configure a server-side API key only when you intend to request live transcription.** + +See the [API pricing page](https://www.listennotes.com/api/pricing/#on-demand-transcription) for included minutes and rates. Use the estimate endpoint to check your account's quota and estimated charge. + +Returns HTTP 202 for a queued or processing request, or HTTP 200 if a completed transcript already exists for this API account. Repeating a pending or completed request reuses it without another transcription charge. If transcription fails, you may request it again. Up to three pending requests are allowed per API account by default. + +Both responses include `transcription_quota_this_cycle` and `billing_this_transcription`. HTTP 202 includes `estimate`, which is null when duration metadata is unavailable. HTTP 200 includes the measured duration and completion time. Use the polling endpoint for signed download URLs. + +Poll GET /episodes/{id}/transcript, or [configure a webhook in the dashboard](https://www.listennotes.com/api/dashboard/#webhooks) to receive `episode_transcription.completed` or `episode_transcription.failed`. Webhooks are optional; there is no webhook URL parameter on this operation. + +The processing deadline is 15 minutes when estimated audio length is under 60 minutes or unknown, otherwise 25% of estimated audio length. Failed and timed-out transcriptions are not charged a transcription fee. + +The per-minute rate is saved when the request is accepted. When a transcription succeeds, we round the measured audio duration up to a whole minute. Only minutes beyond the included quota incur a transcription fee. Disabling Transcription blocks new requests. Accepted requests continue processing. + +No request body is required. Normal API request accounting applies even when the transcription fee is zero. + +```ruby +require "podcast_api" + +client = PodcastApi::Client.new(api_key: nil) +response = client.transcribe_episode(**{ + 'id' => '1871d978bdc648588441bc5649857ddb' +}) +puts response.parsed_response +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#post-api-v2-episodes-id-transcript) + +### get_episode_transcript + +Get episode transcription status and downloads + +`GET /episodes/{id}/transcript` + +Poll the transcription requested by your API account for this episode. Returns HTTP 200 for queued, processing, completed, and failed states. Only your API account's requests are accessible. + +Queued and processing responses include the same quota, billing, and estimate fields as HTTP 202 from POST, plus a `Retry-After` header of 30 seconds. Completed responses include actual duration, `billing_this_transcription`, `transcription_quota_this_cycle`, and all available TXT, SRT, VTT, and word-level JSON download URLs. Failed responses include `error.code`, such as `transcription_timeout`, and null billing minutes and amount. + +Signed URLs in `download_urls` are valid for 15 minutes and share the UTC expiration time in `download_url_expired_date`. Anyone holding a valid URL can download the file without an API key. Poll again for fresh URLs. + +Transcription uses speaker diarization to distinguish voices. When multiple speakers are detected, TXT, SRT, and VTT use speaker labels. A TXT download places the label before the spoken text. + +``` +Speaker A: Thanks for joining us. + +Speaker B: Happy to be here. +``` + +Word-level JSON includes start and end timestamps in milliseconds and a `speaker` ID for each word, or `null` when a label is unavailable. + +If multiple attempts exist, an existing completed transcript remains available until a replacement succeeds. Otherwise the latest request is returned. This operation does not initiate transcription. + +```ruby +require "podcast_api" + +client = PodcastApi::Client.new(api_key: ENV["LISTEN_API_KEY"]) +response = client.get_episode_transcript(**{ + 'id' => '1871d978bdc648588441bc5649857ddb' +}) +puts response.parsed_response +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-episodes-id-transcript) + +### list_transcripts + +List completed episode transcripts + +`GET /transcripts` + +List your API account's completed transcripts, newest completion first. Queued, processing, failed, and superseded attempts are excluded. + +Follow `next_cursor` until it is null. Cursors are opaque and belong to this API account. Each item contains a `billing_this_transcription` summary. Fetch its `transcript_url` from the API server for quota details and fresh signed download URLs. + +```ruby +require "podcast_api" + +client = PodcastApi::Client.new(api_key: ENV["LISTEN_API_KEY"]) +response = client.list_transcripts(**{ + 'limit' => 20 +}) +puts response.parsed_response +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-transcripts) + diff --git a/lib/api-contract.json b/lib/api-contract.json index 6fbfffe..6084928 100644 --- a/lib/api-contract.json +++ b/lib/api-contract.json @@ -1,6 +1,6 @@ { "schema_version": 1, - "version": "3.1.0", + "version": "3.2.0", "operations": [ { "operationId": "search", @@ -394,7 +394,7 @@ "show_transcript": 1 }, "summary": "Fetch detailed meta data for an episode by id", - "description": "Fetch detailed meta data for a specific episode." + "description": "Fetch detailed metadata for a specific episode.\n\nExisting episode transcripts are already available on Listen Notes and include transcripts supplied by podcast producers. About 12% of new episodes and over 3% of all episodes have an existing transcript. Retrieve one with `show_transcript=1` on PRO and ENTERPRISE.\n\nIf an episode has no transcript, use `POST /episodes/{id}/transcript` to request on-demand transcription on any plan." }, { "operationId": "getEpisodesInBatch", @@ -925,6 +925,87 @@ }, "summary": "Update notes for a playlist item.", "description": "Replace item notes, or send an empty string to clear them. The item ID and added_at_ms remain unchanged.\n\nOnly playlists owned by your admin API account can be modified; contributor membership does not grant write access." + }, + { + "operationId": "estimateEpisodeTranscription", + "func": "estimate_episode_transcription", + "available_from": "3.2.0", + "method": "GET", + "path": "/episodes/{id}/transcript/estimate", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true + } + ], + "example_params": { + "id": "dc09fd798802477b8dba0ca1e10134fa" + }, + "summary": "Estimate episode transcription cost", + "description": "Get an informational estimate using episode duration metadata, your remaining quota, and your account's per-minute overage rate. This does not start transcription or reserve quota.\n\n`transcription_quota_this_cycle` shows the included and remaining minutes. `billing_this_transcription.amount_cents` is the estimated fee for minutes beyond the remaining quota. It is 0 when the estimate fits within the quota.\n\nThe final fee uses the audio duration measured by the model, the quota available when transcription completes, and the per-minute rate saved when the request is accepted.\n\nIf duration metadata is unavailable, `estimate`, `billing_this_transcription.billable_minutes`, and `billing_this_transcription.amount_cents` are null. You can request an estimate before enabling Transcription or adding a payment method. Normal API request accounting applies." + }, + { + "operationId": "transcribeEpisode", + "func": "transcribe_episode", + "available_from": "3.2.0", + "method": "POST", + "path": "/episodes/{id}/transcript", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true + } + ], + "example_params": { + "id": "1871d978bdc648588441bc5649857ddb" + }, + "summary": "Request episode transcription", + "description": "Generate speaker-labeled transcripts for a podcast episode on demand. The request runs asynchronously. Ensure Transcription is enabled and a payment method is added in the [API dashboard](https://www.listennotes.com/api/dashboard/#transcription). Eligible paid accounts may use their existing invoicing arrangement.\n\n**On-demand transcription can incur fees. To prevent accidental charges, Run returns a mock response here. Copy the code to request transcription from your own environment.**\n\nSee the [API pricing page](https://www.listennotes.com/api/pricing/#on-demand-transcription) for included minutes and rates. Use the estimate endpoint to check your account's quota and estimated charge.\n\nReturns HTTP 202 for a queued or processing request, or HTTP 200 if a completed transcript already exists for this API account. Repeating a pending or completed request reuses it without another transcription charge. If transcription fails, you may request it again. Up to three pending requests are allowed per API account by default.\n\nBoth responses include `transcription_quota_this_cycle` and `billing_this_transcription`. HTTP 202 includes `estimate`, which is null when duration metadata is unavailable. HTTP 200 includes the measured duration and completion time. Use the polling endpoint for signed download URLs.\n\nPoll GET /episodes/{id}/transcript, or [configure a webhook in the dashboard](https://www.listennotes.com/api/dashboard/#webhooks) to receive `episode_transcription.completed` or `episode_transcription.failed`. Webhooks are optional; there is no webhook URL parameter on this operation.\n\nThe processing deadline is 15 minutes when estimated audio length is under 60 minutes or unknown, otherwise 25% of estimated audio length. Failed and timed-out transcriptions are not charged a transcription fee.\n\nThe per-minute rate is saved when the request is accepted. When a transcription succeeds, we round the measured audio duration up to a whole minute. Only minutes beyond the included quota incur a transcription fee. Disabling Transcription blocks new requests. Accepted requests continue processing.\n\nNo request body is required. Normal API request accounting applies even when the transcription fee is zero." + }, + { + "operationId": "getEpisodeTranscript", + "func": "get_episode_transcript", + "available_from": "3.2.0", + "method": "GET", + "path": "/episodes/{id}/transcript", + "parameters": [ + { + "name": "id", + "in": "path", + "required": true + } + ], + "example_params": { + "id": "1871d978bdc648588441bc5649857ddb" + }, + "summary": "Get episode transcription status and downloads", + "description": "Poll the transcription requested by your API account for this episode. Returns HTTP 200 for queued, processing, completed, and failed states. Only your API account's requests are accessible.\n\nQueued and processing responses include the same quota, billing, and estimate fields as HTTP 202 from POST, plus a `Retry-After` header of 30 seconds. Completed responses include actual duration, `billing_this_transcription`, `transcription_quota_this_cycle`, and all available TXT, SRT, VTT, and word-level JSON download URLs. Failed responses include `error.code`, such as `transcription_timeout`, and null billing minutes and amount.\n\nSigned URLs in `download_urls` are valid for 15 minutes and share the UTC expiration time in `download_url_expired_date`. Anyone holding a valid URL can download the file without an API key. Poll again for fresh URLs.\n\nTranscription uses speaker diarization to distinguish voices. When multiple speakers are detected, TXT, SRT, and VTT use speaker labels. A TXT download places the label before the spoken text.\n\n```\nSpeaker A: Thanks for joining us.\n\nSpeaker B: Happy to be here.\n```\n\nWord-level JSON includes start and end timestamps in milliseconds and a `speaker` ID for each word, or `null` when a label is unavailable.\n\nIf multiple attempts exist, an existing completed transcript remains available until a replacement succeeds. Otherwise the latest request is returned. This operation does not initiate transcription." + }, + { + "operationId": "listTranscripts", + "func": "list_transcripts", + "available_from": "3.2.0", + "method": "GET", + "path": "/transcripts", + "parameters": [ + { + "name": "limit", + "in": "query", + "required": false + }, + { + "name": "cursor", + "in": "query", + "required": false + } + ], + "example_params": { + "limit": 20 + }, + "summary": "List completed episode transcripts", + "description": "List your API account's completed transcripts, newest completion first. Queued, processing, failed, and superseded attempts are excluded.\n\nFollow `next_cursor` until it is null. Cursors are opaque and belong to this API account. Each item contains a `billing_this_transcription` summary. Fetch its `transcript_url` from the API server for quota details and fresh signed download URLs." } ] } diff --git a/lib/api_methods.rb b/lib/api_methods.rb index b09501f..b480acd 100644 --- a/lib/api_methods.rb +++ b/lib/api_methods.rb @@ -158,5 +158,25 @@ def update_playlist_item_notes(**kwargs) [], kwargs) end + def estimate_episode_transcription(**kwargs) + request_api('GET', '/episodes/{id}/transcript/estimate', + [], kwargs) + end + + def transcribe_episode(**kwargs) + request_api('POST', '/episodes/{id}/transcript', + [], kwargs) + end + + def get_episode_transcript(**kwargs) + request_api('GET', '/episodes/{id}/transcript', + [], kwargs) + end + + def list_transcripts(**kwargs) + request_api('GET', '/transcripts', + ['limit', 'cursor'], kwargs) + end + end end diff --git a/lib/version.rb b/lib/version.rb index e45d6b8..3f638d9 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module PodcastApi - VERSION = '3.1.0' + VERSION = '3.2.0' end diff --git a/tests/integration/mock_api_test.rb b/tests/integration/mock_api_test.rb index 3664db0..901b34c 100644 --- a/tests/integration/mock_api_test.rb +++ b/tests/integration/mock_api_test.rb @@ -57,7 +57,11 @@ def assert_response(response, method, path, status = 200) define_method("test_mock_#{operation.fetch('func')}") do params = operation.fetch('example_params').dup path = operation.fetch('path').gsub(/\{([^}]+)\}/) { params.delete(Regexp.last_match(1)).to_s } - status = %w[createPlaylist addPlaylistItem].include?(operation['operationId']) ? 201 : 200 + status = case operation['operationId'] + when 'createPlaylist', 'addPlaylistItem' then 201 + when 'transcribeEpisode' then 202 + else 200 + end response = @client.public_send(operation.fetch('func'), **operation.fetch('example_params')) payload = assert_response(response, operation.fetch('method'), path, status) unless %w[POST PUT].include?(operation['method']) @@ -78,6 +82,11 @@ def assert_response(response, method, path, status = 200) elsif operation['operationId'] == 'deletePlaylistItem' assert_equal true, payload.fetch('deleted') assert_kind_of Integer, payload.fetch('id') + elsif operation['operationId'] == 'transcribeEpisode' + assert_equal 'queued', payload.fetch('status') + elsif operation['operationId'] == 'getEpisodeTranscript' + assert_equal 'completed', payload.fetch('status') + assert_not_empty payload.fetch('download_urls') elsif operation['operationId'] == 'deletePlaylist' assert_equal true, payload.fetch('deleted') assert_equal operation.fetch('example_params').fetch('id'), payload.fetch('id')