Sending a pdf to the /v1/audio/speech endpoint will return audio of the full PDF.
Sending audio to the /v1/audio/speech endpoint will return audio in the voice selected.
import openai
openai.base_url = "http://localhost:8091/v1/"
openai.api_key = "your api key"
pdf_path = "C:\\book.pdf"
with open(pdf_path, "rb") as file:
base64_encoded_pdf = base64.b64encode(file.read()).decode("utf-8")
base64_output = f"data:application/pdf;base64,{base64_encoded_pdf}"
# If it is an audio file, it would be data:audio/wav;base64,.......
tts_response = openai.audio.speech.create(
model="tts-1",
voice="Morgan_Freeman",
input=base64_output,
user="Title of audio",
)
# tts_response will be a URL with the audio. Depending on size of PDF, this will take awhile.
print(tts_response)
Add PDF to Audio and Audio to Audio
/v1/audio/speech
endpoint will return audio of the full PDF./v1/audio/speech
endpoint will return audio in the voice selected.