Silly temp tts (using external pipenv until coqui 3.10 compat)
This commit is contained in:
parent
9937951e69
commit
c3b847bf78
1 changed files with 39 additions and 0 deletions
39
ovtk_audiencekit/plugins/TTS.py
Normal file
39
ovtk_audiencekit/plugins/TTS.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import subprocess
|
||||
import uuid
|
||||
import os.path
|
||||
|
||||
from ovtk_audiencekit.plugins import PluginBase
|
||||
from ovtk_audiencekit.plugins.AudioAlert import Clip
|
||||
from ovtk_audiencekit.events import Message, SysMessage
|
||||
from ovtk_audiencekit.core.Config import CACHE_DIR
|
||||
|
||||
|
||||
class Plugin(PluginBase):
|
||||
def __init__(self, *args, output=None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._output_index = Clip.find_output_index(output)
|
||||
|
||||
def run(self, text, *args, engine="tts_models/en/ljspeech/tacotron2-DDC", _ctx={}, **kwargs):
|
||||
super().run(*args, **kwargs)
|
||||
|
||||
filename = os.path.join(CACHE_DIR, f'{uuid.uuid1()}.wav')
|
||||
|
||||
try:
|
||||
cmd = ['pipenv', 'run', 'tts',
|
||||
'--text', text,
|
||||
'--model_name', engine,
|
||||
'--out_path', filename]
|
||||
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL, cwd='/home/streamo/Documents/tts')
|
||||
except subprocess.CalledProcessError:
|
||||
if source_event := _ctx.get('event'):
|
||||
msg = SysMessage(self._name, 'Failed to make speech from input!!')
|
||||
|
||||
if isinstance(source_event, Message):
|
||||
msg.replies_to = source_event
|
||||
self.chats[source_event.via].send(msg)
|
||||
else:
|
||||
self.chats[source_event.via].send(msg)
|
||||
return
|
||||
|
||||
clip = Clip(filename, self._output_index, speed=0.666)
|
||||
clip.play()
|
Loading…
Add table
Reference in a new issue