[Multiprocessing] Receiving output from the TTS process (only messages belonging to the current session)
()
| 815 | log("info", "TTS sender thread stopped") |
| 816 | |
| 817 | def tts_receiver_thread_func(): |
| 818 | """[Multiprocessing] Receiving output from the TTS process (only messages belonging to the current session)""" |
| 819 | log("info", f"TTS receiver thread started for session {this_uuid}") |
| 820 | |
| 821 | while not close: |
| 822 | try: |
| 823 | try: |
| 824 | uuid_str, speech_array = tts_output_queue.get(timeout=0.1) |
| 825 | except: |
| 826 | continue |
| 827 | |
| 828 | with tts_state_lock: |
| 829 | current_uuid = this_uuid |
| 830 | |
| 831 | if uuid_str != current_uuid: |
| 832 | log("info", f"Discarding TTS output from old session {uuid_str[:8]}... (current: {current_uuid[:8]}...)") |
| 833 | continue |
| 834 | |
| 835 | with audio_buffer_lock: |
| 836 | all_generated_audio.append(speech_array.copy()) |
| 837 | audio_buffer_list.append(speech_array.copy()) |
| 838 | |
| 839 | timestamp = datetime.now().strftime("%H:%M:%S.%f")[:-3] |
| 840 | log("info", f"[{timestamp}] Received TTS audio: {speech_array.shape[-1]} samples") |
| 841 | |
| 842 | except Exception as e: |
| 843 | log("error", f"TTS receiver thread error: {e}") |
| 844 | import traceback |
| 845 | traceback.print_exc() |
| 846 | |
| 847 | log("info", "TTS receiver thread stopped") |
| 848 | |
| 849 | def encode_thread_func(): |
| 850 | """Encoding thread: Take complete frames from audio_buffer, encode them into Opus, and place them into opus_bytes_queue""" |