Skip to content

Text to Speech#

Overview#

A built in speech library may be (dynamically) loaded at run time by setting the setting speech-api to platform.

  • Posix: espeak-ng (or legacy espeak)
  • Windows: SAPI (Microsoft Speech API).

Otherwise, an external TTS (Text to speech) application may be defined by the --voice-command option.

In most cases, using speech-api set to platform will be sufficient. Note that an external program defined by --voice-command overrides the setting speech-api.

External Commands#

Any external speech command should:

  • Read lines of text to be spoken from stdin (standard input)
  • Directly output the synthesised speech
  • Only require invoking once, reading stdin for new text until it is closed.

External command usage#

The simplest way is to add a --voice-command line to your cmdopts file.

Examples:

## Speech Dispatcher
--voice-command="spd-say -t female2 -e"

piper-tts and aplay (ALSA)#

## piper-tts
### Generate a helper script:
$ cat ~/.local/bin/piper-vox.sh
#!/bin/bash

VMODEL=/usr/share/piper-voices/en/en_GB/jenny_dioco/medium/en_GB-jenny_dioco-medium.onnx
piper-tts  --model $VMODEL --output-raw | aplay -q -r 22050 -f S16_LE -t raw -

### Set this as the voice command (in ~/.config/mwp/cmdopts)
### assuming ~/.local/bin is in $PATH
### (or set path explicitly)

--voice-command=piper-vox.sh

piper-tts and pw-play (Pipewire)#

## piper-tts
### Generate a helper script:
$ cat ~/.local/bin/piper-pw.sh
#!/bin/bash

VMODEL=/usr/share/piper-voices/en/en_GB/jenny_dioco/medium/en_GB-jenny_dioco-medium.onnx
piper-tts  --model $VMODEL --output-raw | pw-play --raw --rate 22050 --channel-map LE -

### Set this as the voice command (in ~/.config/mwp/cmdopts)
### assuming ~/.local/bin is in $PATH
### (or set path explicitly)

--voice-command=piper-pw.sh