Learn how to transform PDF documents into engaging multi-speaker conversations
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:
# 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}")else:print(f"Failed to generate PlayNote: {response.text}")
4
Poll for Completion
Check the status of your PlayNote generation:
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 completionwhileTrue: 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'])breakelif status =='generating':print("Please wait, your PlayNote is still generating...") time.sleep(120)# Wait for 2 minutes before polling againelse:print("PlayNote creation failed, please try again.")breakelse:print(f"Error polling for PlayNote status: {response.text}")break
5
Run and Test
Follow these steps to run your code:
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
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 completionwhileTrue: 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'])breakelif status =='generating':print("Please wait, your PlayNote is still generating...") time.sleep(120)# Wait for 2 minutes before polling againelse:print("PlayNote creation failed, please try again.")breakelse: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.