Last active
May 30, 2019 21:08
-
-
Save edo9k/92dcb66d29624539dec33535206eaa12 to your computer and use it in GitHub Desktop.
Gets text from clipboard and reads in the detected language (using the espeak tts system).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# speak.py | |
# | |
# Copyleft 2016 Eduardo França <@edo9k> | |
# | |
# to install | |
# $ sudo apt install python-pip | |
# $ pip install future langdetect pyperclip sh | |
# | |
from __future__ import unicode_literals | |
from __future__ import print_function | |
from sh import espeak | |
from langdetect import detect | |
import pyperclip | |
def do_the_synth(text_line, language, speed): | |
espeak('-v', language, '-s', speed, text_line) | |
def main(args): | |
if len(args) > 1: | |
if args[1] == '--speed': | |
speed = int(args[2]) | |
else: | |
speed = 360 # reading speed | |
text = pyperclip.paste() | |
language = detect(unicode(text)) # detect text language | |
text = text.split('\n') | |
text = list(filter(None, text)) # remove empty lines | |
for index, line in enumerate(text): | |
print("{}\n[{}/{}]".format(line, (index + 1), len(text))) | |
do_the_synth(line, language, speed) | |
return 0 | |
if __name__ == '__main__': | |
import sys | |
try: | |
sys.exit(main(sys.argv)) | |
except KeyboardInterrupt: | |
print("\n") | |
except Exception: | |
traceback.print_exc(file=sys.stdout) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Stuff to add: