(self)
| 203 | logger.warning(f"Model runner set pause signal for action switch & blank status") |
| 204 | |
| 205 | def recv_loop(self): |
| 206 | while True: |
| 207 | try: |
| 208 | message = self.w2f_socket.recv() |
| 209 | except Exception: |
| 210 | logger.error(f"Error receiving message: {traceback.format_exc()}") |
| 211 | break |
| 212 | try: |
| 213 | message = BSON.decode(message) |
| 214 | msg_type = message["type"] |
| 215 | # logger.debug("Received message type: {}".format(msg_type)) |
| 216 | if msg_type == "AgentAudio": |
| 217 | audio = message["audio"] |
| 218 | if audio["type"] != "Pcm": |
| 219 | logger.error("Unsupported audio type: {}".format(audio["type"])) |
| 220 | continue |
| 221 | pcm_data = audio["data"] |
| 222 | audio_info = AudioInfo(audio["info"]) |
| 223 | # logger.debug("Received audio with duration: {}".format(audio_info.duration())) |
| 224 | if self.audio_info is None: |
| 225 | self.audio_info = audio_info |
| 226 | else: |
| 227 | # check if the audio info is the same |
| 228 | if not self.audio_info.is_spec_equal(audio_info): |
| 229 | raise ValueError("Audio info mismatch") |
| 230 | self.audio_buffer.add(pcm_data) |
| 231 | # if status is blank and has voice, set immediate switch to 1 |
| 232 | if self.status == "blank" and self.has_voice(self.seg_duration): |
| 233 | self.immediate_switch_to("voice") |
| 234 | elif msg_type == "AgentStartPlay": |
| 235 | logger.debug("Received AgentStartPlay, create new audio buffer") |
| 236 | self.audio_buffer = ByteBuffer() |
| 237 | elif msg_type == "AgentEndPlay": |
| 238 | logger.debug("Received AgentEndPlay, mark audio finished") |
| 239 | self.audio_buffer.mark_finished() |
| 240 | elif msg_type == "ClearAgentAudio": |
| 241 | logger.warning("Received ClearAgentAudio, clear audio buffer") |
| 242 | self.audio_buffer = None |
| 243 | self.audio_info = None |
| 244 | if self.status == "voice": |
| 245 | self.status = "blank" |
| 246 | # self.immediate_switch_to("blank") |
| 247 | except Exception as e: |
| 248 | logger.error("Error decoding message: {}, continue".format(e)) |
| 249 | continue |
| 250 | logger.warning("recv loop interrupted") |
| 251 | |
| 252 | def start(self): |
| 253 | self.launch_chat_server() |
nothing calls this directly
no test coverage detected