Read Text Extension and Piper TTS

Read Text Extension dialog in LibreOffice using Ubuntu 20.04 LTS

If piper is in your system PATH then the Read Text Extension 0.8.70 dialog will show an option to use it for streaming locally generated neural text to speech.

Summary

Piper TTS

This client reads a text file aloud using piper-tts.

Piper TTS is a fast, private local neural text to speech engine. Users can create or refine voice models based on a recording of a voice.

This client uses the piper engine to read text aloud using Read Text Extension with your office program.

Read Selection... Dialog setup:

External program:

/usr/bin/python3

Use the first available voice.

"(PIPER_READ_TEXT_PY)"  --rate 100% --language (SELECTION_LANGUAGE_CODE) "(TMP)"

Use a particular model (auto5) and speaker (45):

"(PIPER_READ_TEXT_PY)" --voice auto5#45 --rate 75% --language (SELECTION_LANGUAGE_CODE) "(TMP)"

Install piper-tts

If you are not online, then you cannot download voice models or configuration files. Once they are installed, piper handles speech locally.

Binary release

The binary release is available for several platforms and it is fast.

Install the following packages:

python3-pipx

espeak-ng-data

The most recent binary piper executable program included in a piper archive for your computer's specific processor type. For example, piper_linux_x86_64.tar.gz works with x86_64 processors.

For example, for the piper_linux_x86_64 2023.11.14-2 release, use the following:

python3 -c "import os;os.makedirs(os.path.expanduser('~/.local/share/piper-tts/'))"

python3 -c "from urllib import request;import os;request.urlretrieve(\

        'https://github.com/rhasspy/piper/releases/download/2023.11.14-2/piper_linux_x86_64.tar.gz',\

        os.path.expanduser(\

            '~/piper_linux_x86_64.tar.gz'))"

tar -xf ~/piper_linux_x86_64.tar.gz -C ~/.local/share/piper-tts/

ln -s -T ~/.local/share/piper-tts/piper/piper ~/.local/bin/piper-cli

pipx ensurepath

~/.local/bin/piper-cli --version

You can use the following if you do not plan to also install the python release:

ln -s -T ~/.local/share/piper-tts/piper/piper ~/.local/bin/piper

Python release

The python pipx package has higher latency, but the piper script simplifies automating downloading the required onnx data and json configuration files. Some Linux platforms use python versions that are incompatible or only partially compatible with the pipx stable release of piper-tts.

Install the following packages:

python3-pipx

espeak-ng-data

Then use pipx to install piper-tts

pipx update-all

pipx install piper-tts

pipx ensurepath

piper -h

Audition and download a voice model

You can check the voice models online.

Review the voice model samples.

The first time you use this client, it will set up a directory to store piper voice models (onnx) and configuration files (json).

~/.local/share/piper-tts/piper-voices

You can download the voice and configuration files for various languages and regions following the link on the piper-samples web page. Move the onnx and json files to the local piper-voices directory.

Read the README file in the directory for more information about using voice models for other languages and regions.

System-wide installation

If you want every account on a single computer to have access to piper then locate the contents of piper_amd64.tar.gz or the equivalent for your computer architecture in a directory that every account has read access to and link the piper application from the archive to a location that is in every user's PATH environment. For example,

sudo ln -s -T /opt/piper-tts/piper/piper /usr/local/bin/piper


If this piper client does not find user installed models and configuration files, it looks for global models and configuration files in:

/usr/local/share/piper-voices


Users can access the model in the directory from the client dialog using:

"(PIPER_READ_TEXT_PY)" --voice auto0#0 --rate 100% --language (SELECTION_LANGUAGE_CODE) "(TMP)"


If your Linux distribution includes packages to link speech-dispatcher with piper-tts, then you can configure the speech-dispatcher platform to use piper-tts:

"(SPD_READ_TEXT_PY)" --language "(SELECTION_LANGUAGE_CODE)" "(TMP)"


Read Text Extension

Details

python-pipx

To install piper-tts using pipx, you need the python3-pipx and the espeak-ng-data packages.

pipx upgrade-all

pipx install piper-tts

pipx ensurepath

piper -h


Some platforms might show an error when attempting to use the library because they use an incompatible version of one or more of python's support libraries or the system architecture is incompatible with piper-tts. In this case, a binary package compatible with your computer's architecture might work.

Currently, the python library version of the piper command line interface displays no information about the audio stream.

If you have installed the piper-tts library, you can use the following commands to install specific voice models.

sudo apt-get install espeak-ng-data

cd ~/.local/share/piper-tts/piper-voices

echo 'A rainbow is a meteorological phenomenon.' | \

    ~/.local/bin/piper --model en_GB-vctk-medium \

    --output-raw | \

    aplay -r 22050 -f S16_LE -t raw -

The features of the python version of piper can vary depending on the version of python and the libraries that are supplied by your distribution. Therefore, some models that work with the binary version of piper might not work with the python version.

Binary package

The python binary supports Debian stable (x86-64), Fedora Workstation (x86-64) and Ubuntu LTS (x86-64). If you use the binary package, you must include the path to piper in your PATH environment or create a symbolic link to the program path in a directory that is included in your PATH environment.

Download the piper archive and extract the contents to the ~/.local/share/piper-tts directory, so that a piper executable is located at ~/.local/share/piper-tts/piper. This client assumes that the location of the piper executable is in your system path. If ~/.local/share/bin is in your path, then the simplest way to enable the piper command is to create a symbolic link to the file.

ln -s -T ~/.local/share/piper-tts/piper/piper ~/.local/bin/piper-cli

This link command uses a distinct name for the application so that the link does not overwrite a link to a python script of the same name. The binary version of piper displays information about the audio stream in the terminal window.

Create a settings directory manually

If you are using a version of the office suite with restricted permissions or a different version of python than the system python, automated installation of voice model and configuration files might fail.

This client looks for voices in several directories. To create a directory in the recommended location, enter:

mkdir -p "~/.local/share/piper-tts/piper-voices"

cd "~/.local/share/piper-tts/piper-voices"

Download the voices.json configuration file and place it in the root of this new directory.

wget -O "~/.local/share/piper-tts/piper-voices/voices.json" \

    https://huggingface.co/rhasspy/piper-voices/raw/main/voices.json

Within the new piper-voices  directory, you can add valid onnx and json files from your provider or the official piper-tts voices repository. The voices.json  file includes information about the files, including their relative location.

"files": {

    "fr/fr_FR/siwis/low/fr_FR-siwis-low.onnx": {

        "size_bytes": 28130791,

        "md5_digest": "fcb614122005d70f27e4e61e58b4bb56"

    },

    "fr/fr_FR/siwis/low/fr_FR-siwis-low.onnx.json": {

        "size_bytes": 5950,

        "md5_digest": "54392cc51bd08e8aa6270302e9d0180b"

    }, ... }

Using the example, fr_FR-siwis-low.onnx is located on the server at:

https://huggingface.co/rhasspy/piper-voices/resolve/main/fr/fr_FR/siwis/low/fr_FR-siwis-low.onnx

The fr_FR-siwis-low.onnx.json configuration is located on the server at:

https://huggingface.co/rhasspy/piper-voices/resolve/main/fr/fr_FR/siwis/low/fr_FR-siwis-low.onnx.json

This client looks for the local resources in these directories:

~/.local/share/piper-tts/piper-voices/fr/fr_FR/siwis/low/

~/.local/share/piper-tts/piper-voices/

~/piper-voices/

Place fr_FR-siwis-low.onnx and fr_FR-siwis-low.json in one of these directories.

Espeak-ng data

Some voices might require voice data from the espeak-ng package.

Debian family

sudo apt-get install espeak-ng-data

Fedora family

sudo dnf install espeak-ng-data

Optimize voice assets

If you add or erase directories with voice assets, or modify configuration parameters, you can regenerate the local voices.json file with a python script included on the huggingface website.

python3 '($HOME)/.local/share/piper-tts/piper-voices/_script/voicefest.py'

Piper voices have a trade-off between latency and quality. Piper supports four quality levels:

Some models contain multiple speakers. The quality of one of the speakers could be less than it would be using a single speaker model. Contributors and researchers record samples under different conditions, so some voices might have issues like background noise and distortion irrespective of these quality levels .

Git clone

Git is a developer tool to manage computer projects.

Advantages

Disadvantages

Method

cd "~/.local/share/piper-tts/piper-voices"

git clone https://huggingface.co/rhasspy/piper-voices

This method of replicating the developer configuraton setup includes plain text placeholders for the onnx binary files that work with piper-tts. You can activate a voice model by replacing the text placeholder with local symbolic links to local binary onnx files downloaded from the huggingface.co web site.

Placeholder

The placeholder is a text file that contains the version, verification checksum and size of the onnx file. https://huggingface.co/rhasspy/piper-voices/raw/main/en/en_GB/vctk/medium/en_GB-vctk-medium.onnx

Actual file:

The linked file is a binary file that piper-tts can use to generate speech. https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_GB/vctk/medium/en_GB-vctk-medium.onnx

Piper TTS status

If you open the office application in Linux using a command window, then the window will display the current status.

Links


The piper client uses a directory at `~/.local/share/piper-tts/piper-voices` to store onnx data and json configuration files.

The Read Text Extension piper client uses voice models and configuration files stored in a resource directory at `~/.local/share/piper-tts/piper-voices`

Web page that shows samples of Piper TTS voice models

The Piper samples web page lets you preview all the currently published model voices, and open a link to the download site..