diff --git a/README.md b/README.md index c4b73c8..c166c69 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,24 @@ [![Java CI](https://github.com/ListenNotes/podcast-api-java/actions/workflows/gradle.yml/badge.svg)](https://github.com/ListenNotes/podcast-api-java/actions/workflows/gradle.yml) [![Maven Central](https://img.shields.io/maven-central/v/com.listennotes/podcast-api)](https://central.sonatype.com/artifact/com.listennotes/podcast-api) -The official Java client for the [Listen Notes Podcast API](https://www.listennotes.com/podcast-api/), -for JVM applications written in Java, Kotlin, Scala, Groovy, and other languages. -Search podcasts and episodes, fetch metadata, and manage playlists. -Questions? Contact [hello@listennotes.com](mailto:hello@listennotes.com). +Search podcasts and episodes, generate speaker-labeled transcripts on demand, and get podcast audience insights with the official Java SDK for the [Listen Notes Podcast API](https://www.listennotes.com/api/). + +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/). + +## 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) ## Installation @@ -16,7 +30,7 @@ Version 3 requires **Java 17 or later**. It uses the JDK HTTP client and Gradle, with Maven Central enabled: ```groovy -implementation 'com.listennotes:podcast-api:3.1.0' +implementation 'com.listennotes:podcast-api:3.2.0' ``` Maven: @@ -25,11 +39,11 @@ Maven: com.listennotes podcast-api - 3.1.0 + 3.2.0 ``` -These coordinates become installable when 3.1.0 is published to Maven Central. +These coordinates become installable when 3.2.0 is published to Maven Central. ## Usage @@ -182,6 +196,10 @@ separate from creating the draft. Do not store credentials or signing keys in Gi - [`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` @@ -472,7 +490,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. ```java import java.util.HashMap; @@ -1091,6 +1113,150 @@ public class Example { [Full API documentation](https://www.listennotes.com/api/docs/#put-api-v2-playlists-id-items-item_id) +### estimateEpisodeTranscription + +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. + +```java +import java.util.HashMap; +import java.util.Map; +import com.listennotes.podcast_api.Client; +import com.listennotes.podcast_api.exception.ListenApiException; + +public class Example { + public static void main(String[] args) throws ListenApiException { + Client client = new Client(System.getenv("LISTEN_API_KEY")); + Map parameters = new HashMap<>(); + parameters.put("id", "dc09fd798802477b8dba0ca1e10134fa"); + System.out.println(client.estimateEpisodeTranscription(parameters).toJSON().toString(2)); + } +} +``` + +[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. + +```java +import java.util.HashMap; +import java.util.Map; +import com.listennotes.podcast_api.Client; +import com.listennotes.podcast_api.exception.ListenApiException; + +public class Example { + public static void main(String[] args) throws ListenApiException { + Client client = new Client(null); + Map parameters = new HashMap<>(); + parameters.put("id", "1871d978bdc648588441bc5649857ddb"); + System.out.println(client.transcribeEpisode(parameters).toJSON().toString(2)); + } +} +``` + +[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. + +```java +import java.util.HashMap; +import java.util.Map; +import com.listennotes.podcast_api.Client; +import com.listennotes.podcast_api.exception.ListenApiException; + +public class Example { + public static void main(String[] args) throws ListenApiException { + Client client = new Client(System.getenv("LISTEN_API_KEY")); + Map parameters = new HashMap<>(); + parameters.put("id", "1871d978bdc648588441bc5649857ddb"); + System.out.println(client.getEpisodeTranscript(parameters).toJSON().toString(2)); + } +} +``` + +[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. + +```java +import java.util.HashMap; +import java.util.Map; +import com.listennotes.podcast_api.Client; +import com.listennotes.podcast_api.exception.ListenApiException; + +public class Example { + public static void main(String[] args) throws ListenApiException { + Client client = new Client(System.getenv("LISTEN_API_KEY")); + Map parameters = new HashMap<>(); + parameters.put("limit", "20"); + System.out.println(client.listTranscripts(parameters).toJSON().toString(2)); + } +} +``` + +[Full API documentation](https://www.listennotes.com/api/docs/#get-api-v2-transcripts) + ## License diff --git a/gradle.properties b/gradle.properties index af6da5f..4846359 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ GROUP_ID=com.listennotes -VERSION_NAME=3.1.0 +VERSION_NAME=3.2.0 POM_URL=https://github.com/ListenNotes/podcast-api-java POM_SCM_URL=https://github.com/ListenNotes/podcast-api-java diff --git a/src/main/java/com/listennotes/podcast_api/ApiMethods.java b/src/main/java/com/listennotes/podcast_api/ApiMethods.java index 1ebd3cc..907bb60 100644 --- a/src/main/java/com/listennotes/podcast_api/ApiMethods.java +++ b/src/main/java/com/listennotes/podcast_api/ApiMethods.java @@ -334,4 +334,44 @@ public ApiResponse updatePlaylistItemNotes(Map parameters) throw new String[] {"id", "item_id"}, new String[] {}, parameters); } + /** Estimate episode transcription cost + * @param parameters path, query, and form values + * @return API response, including response headers + * @throws ListenApiException on invalid input, connection failure, or a non-2xx response + */ + public ApiResponse estimateEpisodeTranscription(Map parameters) throws ListenApiException { + return requestApi("GET", "/episodes/{id}/transcript/estimate", + new String[] {"id"}, new String[] {}, parameters); + } + + /** Request episode transcription + * @param parameters path, query, and form values + * @return API response, including response headers + * @throws ListenApiException on invalid input, connection failure, or a non-2xx response + */ + public ApiResponse transcribeEpisode(Map parameters) throws ListenApiException { + return requestApi("POST", "/episodes/{id}/transcript", + new String[] {"id"}, new String[] {}, parameters); + } + + /** Get episode transcription status and downloads + * @param parameters path, query, and form values + * @return API response, including response headers + * @throws ListenApiException on invalid input, connection failure, or a non-2xx response + */ + public ApiResponse getEpisodeTranscript(Map parameters) throws ListenApiException { + return requestApi("GET", "/episodes/{id}/transcript", + new String[] {"id"}, new String[] {}, parameters); + } + + /** List completed episode transcripts + * @param parameters path, query, and form values + * @return API response, including response headers + * @throws ListenApiException on invalid input, connection failure, or a non-2xx response + */ + public ApiResponse listTranscripts(Map parameters) throws ListenApiException { + return requestApi("GET", "/transcripts", + new String[] {}, new String[] {"limit", "cursor"}, parameters); + } + } diff --git a/src/test/java/com/listennotes/podcast_api/ClientTest.java b/src/test/java/com/listennotes/podcast_api/ClientTest.java index fe45441..4e90861 100644 --- a/src/test/java/com/listennotes/podcast_api/ClientTest.java +++ b/src/test/java/com/listennotes/podcast_api/ClientTest.java @@ -22,7 +22,7 @@ class ClientTest { @TestFactory Stream everyGeneratedMethodMatchesContract() throws Exception { var operations = TestSupport.operations(); - assertEquals(31, operations.size()); + assertEquals(35, operations.size()); return operations.stream().map(operation -> DynamicTest.dynamicTest(operation.getString("func"), () -> { try (var server = new TestSupport()) { Map parameters = new HashMap<>(); @@ -289,7 +289,7 @@ void legacyConnectionAndResponseConstructorsRemainUsable() throws Exception { Files.writeString(file, matcher.group(1).replace("public class Example", "public class " + name)); arguments.add(file.toString()); } - assertEquals(32, count); + assertEquals(36, count); assertEquals(0, ToolProvider.getSystemJavaCompiler().run(null, null, null, arguments.toArray(String[]::new))); } } diff --git a/src/test/java/com/listennotes/podcast_api/MockIntegrationTest.java b/src/test/java/com/listennotes/podcast_api/MockIntegrationTest.java index 4973dab..0551878 100644 --- a/src/test/java/com/listennotes/podcast_api/MockIntegrationTest.java +++ b/src/test/java/com/listennotes/podcast_api/MockIntegrationTest.java @@ -1,6 +1,5 @@ package com.listennotes.podcast_api; -import java.util.List; import java.util.Map; import java.util.stream.Stream; import org.junit.jupiter.api.*; @@ -13,9 +12,20 @@ class MockIntegrationTest { @TestFactory Stream allMethodsAgainstPublicMock() throws Exception { return TestSupport.operations().stream().map(operation -> DynamicTest.dynamicTest(operation.getString("func"), () -> { ApiResponse response = TestSupport.call(client, operation, TestSupport.examples(operation)); - assertTrue(List.of(200, 201).contains(response.getStatusCode())); + String name = operation.getString("operationId"); + int status = switch (name) { + case "createPlaylist", "addPlaylistItem" -> 201; + case "transcribeEpisode" -> 202; + default -> 200; + }; + assertEquals(status, response.getStatusCode()); assertFalse(response.toJSON().isEmpty()); - if (operation.getString("operationId").equals("deletePlaylist")) { + if (name.equals("transcribeEpisode")) { + assertEquals("queued", response.toJSON().getString("status")); + } else if (name.equals("getEpisodeTranscript")) { + assertEquals("completed", response.toJSON().getString("status")); + assertFalse(response.toJSON().getJSONObject("download_urls").isEmpty()); + } else if (name.equals("deletePlaylist")) { assertEquals(200, response.getStatusCode()); assertTrue(response.toJSON().getBoolean("deleted")); assertEquals(operation.getJSONObject("example_params").getString("id"), response.toJSON().getString("id")); diff --git a/src/test/resources/api-contract.json b/src/test/resources/api-contract.json index 2cf6377..0efcff9 100644 --- a/src/test/resources/api-contract.json +++ b/src/test/resources/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." } ] }