1

I have installed the Foliate ebook reader after installing Ubuntu Base image for Android phone.

I want to use gTTs, which uses Google speech to text service, as its voice is much better than espeak or festival. I have enabled sound in Termux. The script in the Foliate wiki uses play command from sox. However, for some reason, sox does not seem to work because it cannot find audio device (it seems that sox uses ALSA, but only Pulseaudio works with Termux in Android).

How do I use gTTs with Foliate?

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212

1 Answers1

1

This answer does not require a rooted Android device. First start Ubuntu in Termux.

  1. Install gTTs with pip.

    apt install python3-pip
    pip3 install gTTs
    
  2. Install VLC (we would use VLC instead of sox).

    apt install vlc
    

    (mpv does not work because ffmpeg seems to have a bug)

  3. The Ubuntu base image logs in as the root user by default. However, vlc refuses to run as root. Let's allow VLC to run as root, following this answer

    sed -i 's/geteuid/getppid/' /usr/bin/vlc
    
  4. Now, let us modify the script in Foliate wiki to work with VLC.

    The original script was,

    #!/bin/bash
    gtts-cli -l $FOLIATE_TTS_LANG_LOWER --file /dev/stdin | play -t mp3 - &
    trap 'kill $!; exit 0' INT
    wait
    

    I found that $FOLIATE_TTS_LANG_LOWER often creates languages (e.g. en-gb) which are not present in gTTs catalogue. Since I primarily read ebooks in English, I replaced $FOLIATE_TTS_LANG_LOWER --> en.

    Also, by defualt, VLC does not quit after playing a media file. As a result, Foliate cannot automatically turn pages while reading out the text. We need to run the command line version of VLC (cvlc) with the --play-and-exit option.

    The modified script is,

     #!/bin/bash
     gtts-cli -l en --file /dev/stdin | cvlc --play-and-exit - &
     trap 'kill $!; exit 0' INT
     wait
    

    Save this script in /usr/local/bin/gtts, and mark it as executable.

     chmod +x /usr/local/bin/gtts
    
  5. Open Foliate preferences, and enter the command /usr/local/bin/gtts in the field for text-to-speech.

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212