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:binary handlers #5

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 22 additions & 6 deletions hivemind_mic_sat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ovos_bus_client.message import Message

from hivemind_bus_client.client import HiveMessageBusClient
from hivemind_bus_client.client import HiveMessageBusClient, BinaryDataCallbacks
from hivemind_bus_client.message import HiveMessage, HiveMessageType
from hivemind_bus_client.serialization import HiveMindBinaryPayloadType
from ovos_plugin_manager.microphone import OVOSMicrophoneFactory, Microphone
Expand All @@ -14,10 +14,23 @@
from ovos_utils.sound import play_audio


class TTSHandler(BinaryDataCallbacks):
def handle_receive_tts(self, bin_data: bytes,
utterance: str,
lang: str,
file_name: str):
LOG.info(f"Received TTS: {file_name}")
wav = f"/tmp/{file_name}"
with open(wav, "wb") as f:
f.write(bin_data)
play_audio(wav)

JarbasAl marked this conversation as resolved.
Show resolved Hide resolved

class HiveMindMicrophoneClient:

def __init__(self):
self.hm_bus = HiveMessageBusClient()
def __init__(self, prefer_b64=False):
self.prefer_b64 = prefer_b64
self.hm_bus = HiveMessageBusClient(bin_callbacks=TTSHandler())
self.hm_bus.connect(FakeBus())
self.hm_bus.connected_event.wait()
LOG.info("== connected to HiveMind")
Expand Down Expand Up @@ -71,9 +84,12 @@ def handle_rec_end(self, message: Message):

def handle_speak(self, message: Message):
LOG.info(f"SPEAK: {message.data['utterance']}")
m = message.reply("speak:b64_audio", message.data)
if self.prefer_b64:
m = message.reply("speak:b64_audio", message.data)
else:
m = message.reply("speak:synth", message.data)
self.hm_bus.emit(HiveMessage(HiveMessageType.BUS, payload=m))
LOG.debug("Requested base64 encoded TTS audio")
LOG.debug("Requested TTS audio")

def handle_speak_b64(self, message: Message):
LOG.debug("TTS base64 encoded audio received") # TODO - support binary transport too
Expand All @@ -97,7 +113,7 @@ def run(self):
total_silence_duration = 0.0 # in seconds
in_speech = False
max_silence_duration = 6 # silence duration limit in seconds

LOG.info("Listener Loop Started")
while self.running:
chunk = self.mic.read_chunk()
if chunk is None:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
hivemind_bus_client
ovos-plugin-manager
hivemind_bus_client>=0.1.0,<1.0.0
ovos-plugin-manager<1.0.0
Loading