-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Fariello
committed
Feb 21, 2017
1 parent
1b5ba68
commit 7d55af4
Showing
2 changed files
with
12 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
"""TTS for stormbot""" | ||
import os | ||
import subprocess | ||
from gtts import gTTS | ||
from tempfile import NamedTemporaryFile | ||
|
||
from .bot import Plugin | ||
|
||
|
||
class Say(Plugin): | ||
def __init__(self, args): | ||
self.player = args.ttf_player | ||
self.voice = args.say_voice | ||
self.lang = args.say_lang | ||
|
||
@classmethod | ||
def argparse(cls, parser): | ||
parser.add_argument("--ttf-player", type=str, default="espeak", help="Say TTF player (default: %(default)s)") | ||
parser.add_argument("--say-voice", type=str, default="fr-fr", help="Say voice (default: %(default)s)") | ||
parser.add_argument("--say-lang", type=str, default="fr", help="Say lang (default: %(default)s)") | ||
|
||
def parser(self, parser): | ||
subparser = parser.add_parser('say') | ||
subparser.set_defaults(command=self.run) | ||
subparser.add_argument("--voice", type=str, default=self.voice, help="Say voice (default: %(default)s)") | ||
subparser.add_argument("--lang", type=str, default=self.lang, help="Say lang (default: %(default)s)") | ||
subparser.add_argument("text", type=str, help="Text to say") | ||
|
||
def run(self, bot, msg, parser, args): | ||
cmd = [self.player, '-v', self.voice, args.text] | ||
subprocess.Popen(cmd, stdin=None, stdout=None, stderr=None, close_fds=True) | ||
tts = gTTS(text=args.text, lang=args.lang) | ||
with NamedTemporaryFile() as f: | ||
tts.write_to_fp(f) | ||
cmd = ['play', '-t', 'mp3', f.name] | ||
subprocess.check_call(cmd) |