Package: reading4listeners
Reading for Listeners (r4l)I have issues reading pdfs and listening to them helps me out massively! So I'm working on a user-friendly application that can be given a pdf (or txt file) and spit out an MP3 file.
In the future, this'll be a fun server that'll do the hard work, but for now, it'll just be a python/bash project.
This is a small personal project, so there won't be regular updatesper se, but when I have time I'll push what I've got.FeaturesHolistic OCR ImprovementThe biggest problem with PDFs is they either don't have text within the document (are essentially images) or the existing text (usually the result of OCR) is of poor quality.
OCR is often pretty bad on pdfs that I am given, so I use BERT (a masked language model) to improve spell-check results. In future this'll be replaced by Microsoft's TrOCR.TTS with InflectionIf OCR was the only problem, I'd just use make ocrmypdf output to espeak and we'd be done. Unfortunately, espeak sounds terrible. There's no inflection and it'sreallyhard to pay attention to it for long periods of time.
That's whereCoqui.ai's TTScomes to the rescue, making hours-long readings bearable.Always FOSSThe other solutions to this problem are closed source and cost alotof money. This is free.Simple UIEventually this project will have a neat web UI which'll require very little input from the end user.
This is accessibility software after all -- it would be weird if it was hard to use.
Unfortunately, for now I only have a cli which is only been tested on linux. Not the best, but I gotta start somewhere.InstallWindowsThe "easiest" way of doing this is by installingWSLwith Ubuntu and follow the Ubuntu/debian instructions.If you're fancy and know how to python on windows, tell me how it goes and how you did it!Note: unfortunately, it's hard to set up gpu stuff for WSL, and even then only really works for CUDA (NVIDIA) cards, which I have no way of testing as of now (not that I could test any gpu stuff now, but that's beyond the point).MacGotta say, I have no idea how to get all the dependencies (see ubuntu/debian) on mac. A cursory glance says thatbreworportshould be able to get most of them, but I have no idea about their availability. If you have a mac and figured this out, let me know how you did it!Ubuntu/Debiansudo apt install -y python3 python3-venv espeak ffmpeg tesseract-ocr-all python3-dev libenchant-dev libpoppler-cpp-dev pkg-config libavcodec libavtools ghostscript poppler-utilsMake and activate avirtual environment, getpytorch, then runpip install reading4listenersAnd you're all set to runr4l(see below for usage info)Install from sourceOn debian, runsudo apt install -y python3 python3-venv espeak ffmpeg tesseract-ocr-all python3-dev libenchant-dev libpoppler-cpp-dev pkg-config libavcodec libavtools ghostscript poppler-utilsgit clone https://github.com/CypherousSkies/pdf-to-speechcd pdf-to-speechpython3 -m venv venvsouce venv/bin/activatepip install -U pip setuptools wheel cythongetpytorchpython setup.py developTakes ~2-3GB of disk space for installUsager4l [--in_path in/] [--out_path out/] [--lang en]runs the suite of scanning and correction on all compatible files in the directoryin/and  outputs mp3 files toout/using the languageen(square brackets denoting optional parameters with default values).Runr4l --list_langsto list supported languages~~This program uses a lot of memory so I'd advise expanding your swap size by ~10GB (for debian usefixswap.sh)~~ (This should be fixed now, but if it runs out of memory/crashes randomly, increase swap size)BenchmarksOn my current setup (4 intel i7 8th gen cores, no gpu, debian 10, 5gb ram+7gb swap) takes0.124*(word count)-3.8seconds (r^2=0.942,n=6), which is actually pretty good, clocking in at around 10 words per second with some overhead.
Unfortunately, almost all of the pdfs I'm experimenting with are in the 10s of thousands of words, which clocks in at around half an hour, which is less good for getting through my backlog. Ah well.Under the HoodAt a high level, here's how this works:input.pdf -> ocrmypdf (ghostscript -> unpaper -> tesseract-ocr) -> preprocessing (regex) -> ocr correction (BERT) -> postprocessing (regex) -> text to speech (Coqui.ai TTS) -> wav to mp3 (pydub) -> out.mp3Future workI'll almost certainly need to fine-tune TrOCR/BERT and TTS to better deal with the texts I'm interested in when I get access to a ML rig, but until then, I'll keep using the off-the-shelf models.
Hopefully this can all be controlled by a nice, simple web ui and left running on a server for public use.
Also I'd like to package this into an executable which requires minimal technical knowledge to use and maintain, but that's a far-off goal.