Skip to content

Instantly share code, notes, and snippets.

@Chubek
Last active October 3, 2024 01:03
Show Gist options
  • Save Chubek/13cf2ff66ab7e198ad5895197ea22f92 to your computer and use it in GitHub Desktop.
Save Chubek/13cf2ff66ab7e198ad5895197ea22f92 to your computer and use it in GitHub Desktop.
Simple TTS Script based on clipboard

The file speakup.py contains a simple script to do TTS on Linux.

The way you use it is:

1- Install https://github.com/myshell-ai/MeloTTS and pip3 install pyperclip.

2- Install sudo apt-get install xbindkeys

3- Place speakup.py in /etc/speakup.py

4- Edit ~/.xbindkeysrc and add:

"python3 /etc/speakup.py"
  SHIFT + F1

Now whenever you press SHIFT + F1, the text in your clipboard will be spoken up by a very nice lady.

I'm active in systems and language development. I'm starting a 4-year SWE/Compsci degree in a few days. Check my work here.

from melo.api import TTS
from os import system
from pyperclip import paste as paste_clipboard
speed = 1.0
device = 'auto'
model = TTS(language='EN', device=device)
speaker_ids = model.hps.data.spk2id
text = paste_clipboard()
output_path = '/tmp/speakup.wav'
model.tts_to_file(text, speaker_ids['EN-US'], output_path, speed=speed)
system('open /tmp/speakup.wav')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment