Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/b64_tts #58

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions ovos_audio/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import base64
import binascii
import json
import os
import os.path
import time
Expand Down Expand Up @@ -253,6 +255,29 @@ def run(self):
else:
self.status.set_error('No TTS loaded')

def handle_b64_audio(self, message):
"""synthesizes speech, but instead of queuing for playback
returns it b64 encoded in the bus
allows 3rd party integrations to use OVOS as a TTS service
"""
sess = SessionManager.get(message)
stopwatch = Stopwatch()
stopwatch.start()
utterance = message.data['utterance']
JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

ctxt = self.tts._get_ctxt({"message": message})
wav, _ = self.tts.synth(utterance, ctxt)
with open(wav, "rb") as f:
audio = f.read()

b64_audio = base64.b64encode(audio)
self.bus.emit(message.response({"audio": b64_audio}))

stopwatch.stop()
report_timing(sess.session_id, stopwatch,
{'utterance': utterance,
'tts': self.tts.plugin_id})

def handle_speak(self, message):
"""Handle "speak" message

Expand Down Expand Up @@ -294,7 +319,7 @@ def handle_speak(self, message):
stopwatch.stop()
report_timing(sess.session_id, stopwatch,
{'utterance': utterance,
'tts': self.tts.__class__.__name__})
'tts': self.tts.plugin_id})

def _maybe_reload_tts(self):
"""
Expand All @@ -317,7 +342,7 @@ def _maybe_reload_tts(self):
# if fallback TTS is the same as main TTS dont load it
if config.get("module", "") == config.get("fallback_module", "") or not config.get("fallback_module", ""):
LOG.debug("Skipping fallback TTS init, fallback is empty or same as main TTS")
return
return

if not config.get('preload_fallback', True):
LOG.debug("Skipping fallback TTS init")
Expand Down Expand Up @@ -547,6 +572,7 @@ def init_messagebus(self):
self.bus.on('mycroft.audio.queue', self.handle_queue_audio)
self.bus.on('mycroft.audio.play_sound', self.handle_instant_play)
self.bus.on('speak', self.handle_speak)
self.bus.on('speak:b64_audio', self.handle_b64_audio)
self.bus.on('ovos.languages.tts', self.handle_get_languages_tts)
self.bus.on("opm.tts.query", self.handle_opm_tts_query)
self.bus.on("opm.audio.query", self.handle_opm_audio_query)
Expand Down
Loading