Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PDF to Audio and Audio to Audio #37

Merged
merged 5 commits into from
Apr 7, 2024
Merged

Add PDF to Audio and Audio to Audio #37

merged 5 commits into from
Apr 7, 2024

Conversation

Josh-XT
Copy link
Collaborator

@Josh-XT Josh-XT commented Apr 6, 2024

Add PDF to Audio and Audio to Audio

  • 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)

@Josh-XT Josh-XT changed the title Add PDF to Audio Add PDF to Audio and Audio to Audio Apr 6, 2024
@Josh-XT Josh-XT merged commit 0f6bd7c into main Apr 7, 2024
2 checks passed
@Josh-XT Josh-XT deleted the pdf-to-audio branch April 7, 2024 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant