feat: adapt actuation receiver to state's qi_session

Makes actuation tests pass. In main, the timing of the socket no longer contains the time to receive and send data, but only the processing time of the message handler.

ref: N25B-168
This commit is contained in:
Twirre Meulenbelt
2025-10-16 21:46:46 +02:00
parent 56c804b7eb
commit 4c3aa3a911
5 changed files with 91 additions and 17 deletions

View File

@@ -28,20 +28,22 @@ class ActuationReceiver(ReceiverBase):
logging.warn("Received message to speak, but it lacks data.")
return
if not isinstance(text, (str, unicode)):
logging.warn("Received message to speak but it is not a string.")
return
logging.debug("Received message to speak: {}".format(text))
if not state.qi_session: return
# If state has a qi_session, we know that we can import qi
import qi # Takes a while only the first time it's imported
if not self._tts_service:
self._tts_service = state.qi_session.service("ALTextToSpeech")
self._tts_service.say(text)
# Returns instantly. Messages received while speaking will be queued.
qi.async(self._tts_service.say, text)
def handle_message(self, message):
if "endpoint" not in message:
return {"endpoint": "error", "data": "No endpoint provided."}
if message["endpoint"] == "actuate/speech":
self._handle_speech(message)
return {"endpoint": "error", "data": "The requested endpoint is not supported."}

View File

@@ -48,9 +48,6 @@ class MainReceiver(ReceiverBase):
return {"endpoint": "negotiate/error", "data": "The requested endpoint is not implemented."}
def handle_message(self, message):
if "endpoint" not in message:
return {"endpoint": "error", "data": "No endpoint provided."}
if message["endpoint"] == "ping":
return self._handle_ping(message)
elif message["endpoint"].startswith("negotiate"):