p0n1 / epub_to_audiobook

EPUB to audiobook converter, optimized for Audiobookshelf
MIT License
1.04k stars 107 forks source link

(question) All chapters end up being 2kb large #56

Closed f73 closed 3 months ago

f73 commented 6 months ago

Hello,

This is more of a question, then a bug report as I am not sure if this is due to me doing something wrong...

After chapter is converted to mp3 it end up with size of ~2kb, during conversion size is reported correctly (while refreshing directory). This was in wsl on both Ubuntu and Arch distros as well as on regular Linux Arch distro, using python virtual env with edge as tts provider with following command: python main.py book_name.epub book_dir --tts edge --language hr-HR --voice_name hr-HR-SreckoNeural

Had the same issue with english language book, not providing language switch, which, if I am correct use english language by default...

Using conversion with docker image works as expected.

Thanks

fangar commented 6 months ago

Using conversion with docker image works as expected.

I had sent a message on reddit about this and included a link to a sample epub. I am having the same issues with all of my epubs that were originally azw3 and have been converted to epub with calibre. Thanks for the workaround using docker. I will try it next as an alternative.

p0n1 commented 6 months ago

Thanks for reporting. I'll look into this later.

ryanboyd commented 6 months ago

Same issue on my end, running on Windows. I find that if I keyboard interrupt during processing, a more "complete" filesize will appear. In looking at the 2kb files, they do have ID3 tags embedded in them, but it seems like nothing else.

It might be the case that the file is being overwritten with just the tag information at the very end of the write process.

ryanboyd commented 6 months ago

Follow-up: it appears that the issue is in this line: https://github.com/p0n1/epub_to_audiobook/blob/main/audiobook_generator/tts_providers/edge_tts_provider.py#L111

If I comment out the audio.export(audio_fname) call, all works as expected. This line appears to be overwriting the data that is written during generation. After this, the file is still ID3 tagged correctly, leading to the results that I reported above.

fangar commented 6 months ago

If I comment out the audio.export(audio_fname) call, all works as expected.

I can confirm that also does the trick for me; many thanks! I looked through the code, but nothing jumped out at me.

p0n1 commented 6 months ago

Looks like this issue was introduced by https://github.com/p0n1/epub_to_audiobook/pull/45. I haven't make a release for the latest code so the docker version just worked fine.

Thanks everyone for trying and reporting this. Thanks @ryanboyd for your fix. I'll merge soon. But I still don't understand why I can't reproduce this issue. Will try more cases.

devPDG commented 6 months ago

My workaround for this on https://github.com/p0n1/epub_to_audiobook/blob/767f040546bb4f756a2b3025919737bb71a45403/audiobook_generator/tts_providers/edge_tts_provider.py#L95 is

    async def save(
        self,
        audio_fname: Union[str, bytes],
        metadata_fname: Optional[Union[str, bytes]] = None,
    ) -> None:
        # Save the audio and metadata to the specified files.
        await self.chunkify()
        await super().save(audio_fname, metadata_fname)

        audio: AudioSegment = AudioSegment.from_file(audio_fname)
        audio.export(audio_fname)

If you just comment out the audio export, the file size will be larger though, audio export somewhat compresses the audio. though the problem is when you pick other formats like amr, ogg, silk, etc. It seems that its not giving the result as what we have expected, its still just an mp3 with another file extension format, the file spec will still be the same regardless.

A 15573 characters not yet converted by pydub audio.export is 4.92MB while 3.28MB when converted/exported.