Text to speech on Fedora?

When I used Mac, I set up a keyboard shortcut to play highlighted text, great for listing to an article while I do something else. I doubt that feature is available in stock Fedora but wondered if anyone knows of a way to set that up somehow?
thanks

Did you search for 'text to speech on fedora`?
This is the very first link I found and there are many others related.

I’ve never used it, but it looks like Orca has a “Speak current selection” option:

Excerpted from Orca – commands_reading

Text Attributes and Selected Text
Orca has a dedicated command for obtaining the attributes of the text at the caret location. In addition, if you use Orca’s Where Am I commands from within a text object in which text has been selected, Orca will announce the selected text. Orca’s command to speak the current selection will also perform this function in a text object.

Present the text attributes: Orca Modifier+F

Perform basic Where Am I:

Desktop: KP Enter

Laptop: Orca Modifier+Return

Perform detailed Where Am I:

Desktop: KP Enter (double-clicked)

Laptop: Orca Modifier+Return (double-clicked)

Speak current selection: Orca Modifier+Shift+Up

Search where on Fedora?

Going to take me a while to learn what Orca is, which appears to suggest I start by reading all about Gnome first, I will need time for that!
Just wondered if there was a simply utility hidden away I don’t know about (as was the case on Mac for years until I heard about it, and it was there all along!)
thanks

Yes, Orca does a great deal more than just reading screen text and it might be more than what you are looking for and it might depend on GNOME.

espeak is probably one of the simplest text-to-speech tools available on Fedora Linux. You can install it with dnf install espeak. To operate it, you “pipe” text into it. For example, try echo 'hello world' | espeak. If you want to send highlighted text to it, you will need another small utility program to retrieve the currently-highlighted text. That program is called xclip and you can install it with dnf install xclip. You can test xclip by highlighting some text somewhere and then running xclip -o. Finally, you can combine the two by running xclip -o | espeak and whatever text you have highlighted should be read aloud. If you bind a hotkey to the xclip -o | espeak command, you should get a very simple version of what you have asked for. How to bind hotkeys varies depending on the desktop environment you are running. For example, I am running Sway and I can bind the Super+Control+z hotkey to run the xclip -o | espeak command by adding the following line to ~/.config/sway/config and pressing Super+Shift+c to reload my Sway configuration.

bindsym $mod+Control+z exec xclip -o | espeak

Bit scary/complex but in lieu of any other options I will make a note to check back here and see if I can learn that way. thanks

1 Like

I stumbled on this post few days ago where I wanted to set up a good TTS. In particular, I wanted something that sounded more natural than espeak. Here is my current solution, which uses the state-of-the-art model xtts_v2 with coqui-tts.

The solution is suboptimal: it first produces a .wav file and then plays it. It could be improved to a streaming version (somewhere they suggest some docker containers that should set it up, but I didn’t have time to try that out).

I assume you have the xclip command.
First, install coqui-tts (not to be confused with what you get with pip install TTS which is less updated)

python3.11 -m pip install coqui-tts

you can then select any text and run

tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --speaker_idx 'Claribel Dervla' --language_idx en --text "$(xclip -o)" --out_path "/tmp/tts_out_$(date +%Y%m%d_%H%M%S).wav"

:warning: The first time, will download the xtts_v2 model (few GBs).
The above command, as you can see, will produce a .wav in the /tmp folder, which you can play e.g. with paplay /tmp/FILENAME.wav.

You can pack these few commands in a script which you can bind to a shortcut, which has been working good enough for me (the shortcut opens a terminal window so if I want to kill the generation of the file or the playback, I just have to kill the window).

You can

  • set a different language,
  • try different speakers, you get the list with
tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --list_speaker_idxs
  • even clone another voice with the argument --speaker_wav /path/to/target/speaker.wav
  • do much more, read the docs.

Hope this is useful to other people :blue_heart:.

1 Like