From f62a784c6ed0aa8c7a538160a9ad4dc6532a0b00 Mon Sep 17 00:00:00 2001 From: Wenbin Fang Date: Wed, 25 Nov 2026 19:49:09 -0800 Subject: [PATCH 1/2] Add on-demand podcast transcription --- README.md | 158 ++++++++++++++++++++++++++++-- listennotes/ApiMethods.php | 24 +++++ listennotes/Client.php | 2 +- listennotes/api-contract.json | 85 +++++++++++++++- tests/integration/MockApiTest.php | 13 ++- 5 files changed, 271 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 33d0b4c..2ca2e84 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,9 @@ [![PHP CI](https://github.com/ListenNotes/podcast-api-php/actions/workflows/php.yml/badge.svg)](https://github.com/ListenNotes/podcast-api-php/actions/workflows/php.yml) [![Packagist Version](https://img.shields.io/packagist/v/listennotes/podcast-api)](https://packagist.org/packages/listennotes/podcast-api) -The Podcast API PHP library provides convenient access to the [Listen Notes Podcast API](https://www.listennotes.com/podcast-api/) from -applications written in the PHP language. +Search podcasts and episodes, generate speaker-labeled transcripts on demand, and get podcast audience insights with the official PHP 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+PHP+SDK+of+Listen+API) @@ -14,6 +13,21 @@ If you have any questions, please contact [hello@listennotes.com](hello@listenno +## 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 | +| --- | --- | +| [`estimateEpisodeTranscription`](#estimateepisodetranscription) | Estimate cost and check your remaining transcription quota. | +| [`transcribeEpisode`](#transcribeepisode) | Queue a transcription for a podcast episode. | +| [`getEpisodeTranscript`](#getepisodetranscript) | Poll for job status and get fresh signed download URLs. | +| [`listTranscripts`](#listtranscripts) | 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) + ## Methods @@ -49,6 +63,10 @@ If you have any questions, please contact [hello@listennotes.com](hello@listenno - [`addPlaylistItem`](#addplaylistitem) — `POST /playlists/{id}/items` - [`deletePlaylistItem`](#deleteplaylistitem) — `DELETE /playlists/{id}/items/{item_id}` - [`updatePlaylistItemNotes`](#updateplaylistitemnotes) — `PUT /playlists/{id}/items/{item_id}` +- [`estimateEpisodeTranscription`](#estimateepisodetranscription) — `GET /episodes/{id}/transcript/estimate` +- [`transcribeEpisode`](#transcribeepisode) — `POST /episodes/{id}/transcript` +- [`getEpisodeTranscript`](#getepisodetranscript) — `GET /episodes/{id}/transcript` +- [`listTranscripts`](#listtranscripts) — `GET /transcripts` @@ -146,7 +164,7 @@ Use `getStatusCode()` and `getHeaders()` to inspect the latest response. Version 3.0.0 added five playlist write methods; 3.1.0 adds `deletePlaylist`. PHP 8.4 remains the minimum supported version. -The default User-Agent is `podcast-api-php 3.1.0`. Requests have a 30-second total +The default User-Agent is `podcast-api-php 3.2.0`. Requests have a 30-second total timeout and a connection timeout of at most 10 seconds. Pass a positive timeout in seconds as the second constructor argument to change the total timeout. Redirects and automatic request retries are disabled. HTTP 201 and other 2xx @@ -398,7 +416,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. ```php estimateEpisodeTranscription([ + 'id' => 'dc09fd798802477b8dba0ca1e10134fa' +]); +print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR)); +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-episodes-id-transcript-estimate) + +### transcribeEpisode + +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. + +```php +transcribeEpisode([ + 'id' => '1871d978bdc648588441bc5649857ddb' +]); +print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR)); +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#post-api-v2-episodes-id-transcript) + +### getEpisodeTranscript + +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. + +```php +getEpisodeTranscript([ + 'id' => '1871d978bdc648588441bc5649857ddb' +]); +print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR)); +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-episodes-id-transcript) + +### listTranscripts + +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. + +```php +listTranscripts([ + 'limit' => 20 +]); +print_r(json_decode($response, true, 512, JSON_THROW_ON_ERROR)); +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-transcripts) + ## Development @@ -932,5 +1078,5 @@ README sections are generated by the Listen Notes monorepo's `devtools/api-sdks/sync.py php`. Edit the canonical spec/registry there, not these outputs. The SDK, tests, and packaged distribution work independently. -Packagist derives package versions from Git tags. `Client::VERSION` is 3.1.0; +Packagist derives package versions from Git tags. `Client::VERSION` is 3.2.0; publication/tagging is a separate release step after review and CI. diff --git a/listennotes/ApiMethods.php b/listennotes/ApiMethods.php index 230af1d..ca77a5a 100644 --- a/listennotes/ApiMethods.php +++ b/listennotes/ApiMethods.php @@ -192,4 +192,28 @@ public function updatePlaylistItemNotes(array $arrOptions = []): string [], $arrOptions); } + public function estimateEpisodeTranscription(array $arrOptions = []): string + { + return $this->requestApi('GET', '/episodes/{id}/transcript/estimate', + [], $arrOptions); + } + + public function transcribeEpisode(array $arrOptions = []): string + { + return $this->requestApi('POST', '/episodes/{id}/transcript', + [], $arrOptions); + } + + public function getEpisodeTranscript(array $arrOptions = []): string + { + return $this->requestApi('GET', '/episodes/{id}/transcript', + [], $arrOptions); + } + + public function listTranscripts(array $arrOptions = []): string + { + return $this->requestApi('GET', '/transcripts', + ['limit', 'cursor'], $arrOptions); + } + } diff --git a/listennotes/Client.php b/listennotes/Client.php index b0394a0..e8581f5 100644 --- a/listennotes/Client.php +++ b/listennotes/Client.php @@ -6,7 +6,7 @@ final class Client extends Http\Curl { - public const VERSION = '3.1.0'; + public const VERSION = '3.2.0'; use ApiMethods; } diff --git a/listennotes/api-contract.json b/listennotes/api-contract.json index 2cf6377..0efcff9 100644 --- a/listennotes/api-contract.json +++ b/listennotes/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": "estimateEpisodeTranscription", + "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": "transcribeEpisode", + "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": "getEpisodeTranscript", + "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": "listTranscripts", + "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/tests/integration/MockApiTest.php b/tests/integration/MockApiTest.php index 8698d68..bab8ce6 100644 --- a/tests/integration/MockApiTest.php +++ b/tests/integration/MockApiTest.php @@ -79,13 +79,22 @@ public function testAllMethodsAgainstPublicMock(array $op): void $path = preg_replace_callback('/\{([^}]+)\}/', static function ($m) use (&$params) { $value = $params[$m[1]]; unset($params[$m[1]]); return rawurlencode((string) $value); }, $op['path']); - $status = in_array($op['operationId'], ['createPlaylist', 'addPlaylistItem'], true) ? 201 : 200; + $status = match ($op['operationId']) { + 'createPlaylist', 'addPlaylistItem' => 201, + 'transcribeEpisode' => 202, + default => 200, + }; $payload = $this->checkResponse($this->client->{$op['func']}($op['example_params']), $op['method'], $path, $status); if (in_array($op['method'], ['GET', 'DELETE'], true)) { parse_str(parse_url($this->client->getUri(), PHP_URL_QUERY) ?? '', $sent); } else { parse_str($this->client->getRequestBody(), $sent); } self::assertSame(array_map('strval', $params), $sent); - if (in_array($op['operationId'], ['createPlaylist', 'updatePlaylist', 'getPlaylistById'], true)) { + if ($op['operationId'] === 'transcribeEpisode') { + self::assertSame('queued', $payload['status']); + } elseif ($op['operationId'] === 'getEpisodeTranscript') { + self::assertSame('completed', $payload['status']); + self::assertNotEmpty($payload['download_urls']); + } elseif (in_array($op['operationId'], ['createPlaylist', 'updatePlaylist', 'getPlaylistById'], true)) { self::assertIsString($payload['id']); self::assertContains($payload['type'], ['episode_list', 'podcast_list']); self::assertContains($payload['visibility'], ['public', 'unlisted', 'private']); From 093b1cf6a97b499f01ea288e6d08c92abd0339c6 Mon Sep 17 00:00:00 2001 From: Wenbin Fang Date: Wed, 25 Nov 2026 19:51:51 -0800 Subject: [PATCH 2/2] Verify the packaged SDK against its contract --- .github/workflows/php.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 001aa20..65b9f73 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -42,7 +42,26 @@ jobs: test ! -e tests test -f listennotes/api-contract.json composer install --no-dev --no-interaction --no-progress - php -r 'require "vendor/autoload.php"; $client = new ListenNotes\PodcastApi\Client(); if ($client::VERSION !== "3.1.0" || count(get_class_methods(ListenNotes\PodcastApi\ApiMethods::class)) !== 31 || !method_exists($client, "deletePlaylist")) { exit(1); }' + php <<'PHP' +