p0n1 / epub_to_audiobook

EPUB to audiobook converter, optimized for Audiobookshelf
MIT License
894 stars 87 forks source link

OpenAI TTS Support #9

Closed Madnex closed 7 months ago

Madnex commented 8 months ago

Hi! Awesome project :)

Any plans to support TTS by OpenAI as well?

p0n1 commented 8 months ago

Yes. I am trying.

p0n1 commented 7 months ago

Hi @Madnex I just released v0.4.0 with OpenAI TTS support. Any feedback would be greatly appreciated.

Madnex commented 7 months ago

Oh boy that was fast 😱 Will try it out soon 😎👍

iconoclasthero commented 7 months ago

Here's my feedback: https://pastebin.com/HKqTZH4k It errored out on the first try with the very first epub I tried to convert. Do I need to pay for OpenAI? FWIW, the .epub in question is 1,735,742 bytes... I'm not sure what that should translate into characters of text, but somewhere less than a MB I would assume once all the HTML formatting is removed.

p0n1 commented 7 months ago

Here's my feedback: https://pastebin.com/HKqTZH4k

It errored out on the first try with the very first epub I tried to convert. Do I need to pay for OpenAI? FWIW, the .epub in question is 1,735,742 bytes... I'm not sure what that should translate into characters of text, but somewhere less than a MB I would assume once all the HTML formatting is removed.

@iconoclasthero Yes, I think OpenAI doesn't provide a free quota for TTS. You may have to add your credit card or add some credits. You can you the --preview option to get an overview of books. Like '2023-11-10 13:47:19 [INFO] ✨ Total characters in selected chapters: 565900 ✨'.

smeehee88 commented 7 months ago

Hi! love the project. I've been following it for a bit over on reddit. Is there anyway that an option to specify the openai api base url could be added so we can use something like Localai rather than the official openai api?

p0n1 commented 7 months ago

Hi! love the project. I've been following it for a bit over on reddit. Is there anyway that an option to specify the openai api base url could be added so we can use something like Localai rather than the official openai api?

@smeehee88 Sure. I can add an option for custom OpenAI base url. Haven't try LocalAI or something similar. I'm very interested in the LocalAI results, especially on OpenAI TTS compatibility and performance.

p0n1 commented 7 months ago

@smeehee88 I just found the localai TTS is totally different from OpenAI in their API. https://localai.io/features/text-to-audio/ So just changing the base URL of OpenAI API/SDK will not work.

YaibaToKen commented 7 months ago

@smeehee88 I just found the localai TTS is totally different from OpenAI in their API. https://localai.io/features/text-to-audio/ So just changing the base URL of OpenAI API/SDK will not work.

image

This is from their documentation: https://localai.io/basics/getting_started/#python

Assuming I'm understanding this properly, we should already be able to use LocalAI for this just by setting that environment variable, for example, in our docker containers.

p0n1 commented 7 months ago

We could move discussion on LocalAI support to https://github.com/p0n1/epub_to_audiobook/issues/17.

p0n1 commented 7 months ago

This is from their documentation: https://localai.io/basics/getting_started/#python

Assuming I'm understanding this properly, we should already be able to use LocalAI for this just by setting that environment variable, for example, in our docker containers.

@YaibaToKen Not yet I think.

Madnex commented 7 months ago

Hi @p0n1 here my feedback for the current version: Running with just docker did not work. Using this command docker run --rm -v ./:/app -e OPENAI_API_KEY=$OPENAI_API_KEY ghcr.io/p0n1/epub_to_audiobook your_book.epub audiobook_output --tts openai

gave me this: python: can't open file '/app/epub_to_audiobook.py': [Errno 2] No such file or directory

Running with python (venv) gave me this error: ModuleNotFoundError: No module named 'importlib_metadata'. After installing the missing library it worked :) Maybe something to add to requirements.txt?

Besides from that it works like a charm 🚀

p0n1 commented 7 months ago

Hi @p0n1 here my feedback for the current version: Running with just docker did not work. Using this command docker run --rm -v ./:/app -e OPENAI_API_KEY=$OPENAI_API_KEY ghcr.io/p0n1/epub_to_audiobook your_book.epub audiobook_output --tts openai

gave me this: python: can't open file '/app/epub_to_audiobook.py': [Errno 2] No such file or directory

Running with python (venv) gave me this error: ModuleNotFoundError: No module named 'importlib_metadata'. After installing the missing library it worked :) Maybe something to add to requirements.txt?

Besides from that it works like a charm 🚀

Thank you @Madnex!

For docker, the epub_to_audiobook.py source code was override by the mounted docker volume. I didn't catch that because I actually mount in the repo so the container can still find the code in my host. I just pushed a fix with v0.4.2 on this issue. You can retry after updating by docker pull ghcr.io/p0n1/epub_to_audiobook:latest.

For python package, did you use python with version bellow 3.8? I did some search and found it might be related. Just documented it here in case anyone ran into similar issue.

Thanks again for your detailed report. Really helped a lot!

Madnex commented 7 months ago

Thanks a lot for the fix! Docker is working now as expected 🚀

And for python it was 3.9.6 actually. Might indeed be because of that.

Great work!

Madnex commented 7 months ago

Closing as it is implemented 🚀