10

I'm currently using Ubuntu 18.04 and Okular for viewing pdf documents. I thought it would be convenient if I could use the text to speech feature. I tried following all the instructions given here: http://freesoftwaremagazine.com/articles/listen_your_books_epub_pdf_okular/ (which was the only source I could find online) and I'm yet unable to get the text-to-speech feature working. Can you please tell me what should I do to get this working? If it is not possible because it was deprecated, can you please recommend a good alternative?

I tried opening the application from the terminal to listen to the audio. This was the output on the terminal when I selected a part of the text and clicked "Speak Text":

using null output device, none available
qt.speech.tts.flite: "Failed to start audio output (error 1)"
Sreram
  • 659
  • Are you sure that the pdf file contains text? There might be pages, that consist of [scanned] images. Install poppler-utils and run pdftotext your-file.pdf /dev/stdout - Is there any output to the terminal window? If you get output, you can install espeak and run pdftotext your-file.pdf /dev/stdout | espeak. I tested that it works right now. You prefer to store the output text in a file, and grep paragraphs from that file to espeak. Tip: pdftotext your-file.pdf (without output file name and redirection) will write to the file your-file.txt. – sudodus Dec 04 '18 at 12:57
  • @sudodus Yes I ensured that the pdf contains text. And Thanks! I'll try using espeak and pdftotext. – Sreram Dec 04 '18 at 14:46

4 Answers4

2

Qt Multimedia module is not installed by default so you are required to install it.

sudo apt install qml-module-qtmultimedia
2

I followed this instruction set successfully.

Install the dispatcher:

sudo apt-get install speech-dispatcher 

Install the synthesizer:

sudo apt-get install espeak

Install the speech plugin for Okular:

sudo apt-get install qtspeech5-speechd-plugin

Note: in this moment the version of Qt is 5. In the future, when you still read this article, you may find the version changed and the package version or name changed as well. This article is based only on current version.

Run the dispatcher first:

speech-dispatcher -d

You must run Okular after speech-dispatcher.

Zanna
  • 70,465
1

Program packages

Install two packages

sudo apt install poppler-utils espeak

Copy and paste text

If you can

  • copy and paste a piece of text from a pdf document directly or
  • create a text file your-file.txt with

    pdftotext your-file.pdf
    

    and open the text file in a text editor and copy a piece of text from there,

then you can paste the piece of text into a terminal window, where espeak is running.

$ espeak

or if there is annoying warning output

$ espeak 2>/dev/null

Press Enter and espeak will wait for input from the terminal, so copy and paste some text from your pdf file in okular (or from some other program as illustrated with your question's title in my firefox,

The “Speak Text” feature in Okular is not working. How do I get it to work?

Press Enter to start reading aloud. Copy and paste some other pieces of text and press Enter to listen to them. Quit from espeak with ctrl C.

See the screenshot:

enter image description here

Pipe text into espeak

You can redirect the output into espeak and listen to all the text from a pdf file,

pdftotext your-file.pdf /dev/stdout | espeak

or if you have a text file, read from it directly,

< your-file.txt espeak

or if you want a talking clock

LC_TIME=C date '+%A, %B, %-d, %Y; %H and %M' | espeak
sudodus
  • 46,324
  • 5
  • 88
  • 152
1

If nothing else works (which was the case for me), I made a small python program which glues together pdftotext, espeak and aplay: pdf2speech

It's not as good as having the integration with okular, but it works.