Use this file to discover all available pages before exploring further.
This guide will walk you through generating a conversational-style podcast from a PDF using the PlayNote API. We’ll use the PlayNote API to take a PDF source file, synthesize it into an audio conversation between two voices, and retrieve the generated podcast URL.
Create a script with the following authentication setup:
import requestsimport os# Define the URL of your PDF fileSOURCE_FILE_URL = "https://godinton.kent.sch.uk/media/2601/goldilocks-story.pdf"# PlayNote API URLurl = "https://api.play.ai/api/v1/playnotes"# Retrieve API key and User ID from environment variablesapi_key = os.getenv("PLAYAI_API_KEY")user_id = os.getenv("PLAYAI_USER_ID")# Set up headers with authorization detailsheaders = { 'AUTHORIZATION': api_key, 'X-USER-ID': user_id, 'accept': 'application/json'}
3
Send Request to Generate PlayNote
Configure and send the request to create your podcast:
import urllib.parseimport time# Double-encode the PlayNote ID for the URLdouble_encoded_id = urllib.parse.quote(playNoteId, safe='')# Construct the final URL to check the statusstatus_url = f"https://api.play.ai/api/v1/playnotes/{double_encoded_id}"# Poll for completionwhile True: response = requests.get(status_url, headers=headers) if response.status_code == 200: playnote_data = response.json() status = playnote_data['status'] if status == 'completed': print("PlayNote generation complete!") print("Audio URL:", playnote_data['audioUrl']) break elif status == 'generating': print("Please wait, your PlayNote is still generating...") time.sleep(120) # Wait for 2 minutes before polling again else: print("PlayNote creation failed, please try again.") break else: print(f"Error polling for PlayNote status: {response.text}") break
5
Run and Test
Follow these steps to run your code:
Python
JavaScript
Go
Dart
Swift
Save your code as playnote_generator.py
Open terminal in your code directory
Run: python3 playnote_generator.py
Wait for the generation process to complete
Access your generated audio using the provided URL
Save your code as playnote_generator.js
Install dependencies: npm install node-fetch
Run: node playnote_generator.js
Wait for the generation process to complete
Access your generated audio using the provided URL
Save your code as playnote_generator.go
Run: go run playnote_generator.go
Wait for the generation process to complete
Access your generated audio using the provided URL
Save your code as playnote_generator.dart
Install dependencies: dart pub add http
Run: dart run playnote_generator.dart
Wait for the generation process to complete
Access your generated audio using the provided URL
Save your code as playnote_generator.swift
Run: swift playnote_generator.swift
Wait for the generation process to complete
Access your generated audio using the provided URL
import requestsimport osimport urllib.parseimport time# Define the URL of your PDF fileSOURCE_FILE_URL = "https://godinton.kent.sch.uk/media/2601/goldilocks-story.pdf"# PlayNote API URLurl = "https://api.play.ai/api/v1/playnotes"# Retrieve API key and User ID from environment variablesapi_key = os.getenv("PLAYAI_API_KEY")user_id = os.getenv("PLAYAI_USER_ID")# Set up headers with authorization detailsheaders = { 'AUTHORIZATION': api_key, 'X-USER-ID': user_id, 'accept': 'application/json'}# Configure the request parametersfiles = { 'sourceFileUrl': (None, SOURCE_FILE_URL), 'synthesisStyle': (None, 'podcast'), 'voice1': (None, 's3://voice-cloning-zero-shot/baf1ef41-36b6-428c-9bdf-50ba54682bd8/original/manifest.json'), 'voice1Name': (None, 'Angelo'), 'voice2': (None, 's3://voice-cloning-zero-shot/e040bd1b-f190-4bdb-83f0-75ef85b18f84/original/manifest.json'), 'voice2Name': (None, 'Deedee'),}# Send the POST requestresponse = requests.post(url, headers=headers, files=files)if response.status_code == 201: print("Request sent successfully!") playNoteId = response.json().get('id') print(f"Generated PlayNote ID: {playNoteId}") # Double-encode the PlayNote ID for the URL double_encoded_id = urllib.parse.quote(playNoteId, safe='') # Construct the final URL to check the status status_url = f"https://api.play.ai/api/v1/playnotes/{double_encoded_id}" # Poll for completion while True: response = requests.get(status_url, headers=headers) if response.status_code == 200: playnote_data = response.json() status = playnote_data['status'] if status == 'completed': print("PlayNote generation complete!") print("Audio URL:", playnote_data['audioUrl']) break elif status == 'generating': print("Please wait, your PlayNote is still generating...") time.sleep(120) # Wait for 2 minutes before polling again else: print("PlayNote creation failed, please try again.") break else: print(f"Error polling for PlayNote status: {response.text}") breakelse: print(f"Failed to generate PlayNote: {response.text}")
If you encounter issues, check these common problems:
Authentication Issues:
Verify your API key and user ID are correctly set in your environment
Confirm the AUTHORIZATION header is properly formatted
Source File Issues:
Ensure your PDF URL is publicly accessible
Verify the PDF file is not corrupted or password-protected
Generation Time:
The process typically takes 5-10 minutes depending on the PDF size
If the status remains “generating” for an extended period, try creating a new request
API Endpoint Errors:
Verify you’re using the correct PlayNote API endpoint
Check that your request payload matches the expected format
This guide provides a simple yet powerful way to turn text content from a PDF into a rich, conversational podcast format using PlayNote API. Modify the voice parameters to customize the conversation to match your desired style.