DevXT-LLC / ezlocalai

ezlocalai is an easy to set up local artificial intelligence server with OpenAI Style Endpoints.
MIT License
66 stars 12 forks source link

Add PDF to Audio and Audio to Audio #37

Closed Josh-XT closed 3 months ago

Josh-XT commented 3 months ago

Add PDF to Audio and Audio to Audio

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)