MCPcopy Create free account
hub / github.com/FunAudioLLM/Fun-Audio-Chat / tts_sender_thread_func

Method tts_sender_thread_func

web_demo/server/server.py:762–815  ·  view source on GitHub ↗

[Multiprocessing] Send audio tokens to the TTS process

()

Source from the content-addressed store, hash-verified

760 all_recorded_pcm = np.concatenate((all_recorded_pcm, pcm))
761
762 def tts_sender_thread_func():
763 """[Multiprocessing] Send audio tokens to the TTS process"""
764 nonlocal tts_offset, cur_audio_tokens, this_uuid, max_tts_tokens, tts_generation_complete, accumulate_tts_tokens
765
766 token_hop_len = 15
767 pre_lookahead_len = 3
768
769 log("info", "TTS sender thread started")
770
771 while not close:
772 try:
773 finalize = False
774 try:
775 audio_token = audio_tokens_queue.get(timeout=0.1)
776
777 with tts_state_lock:
778 cur_audio_tokens.append(audio_token)
779 if len(cur_audio_tokens) < tts_offset + token_hop_len + pre_lookahead_len:
780 continue
781 except queue.Empty:
782 if tts_generation_complete['flag']:
783 finalize = True
784 frame_generation_complete['flag'] = True
785 with tts_state_lock:
786 if len(cur_audio_tokens) <= tts_offset + 1 + pre_lookahead_len:
787 continue
788 else:
789 continue
790
791 with tts_state_lock:
792 tokens_to_send = cur_audio_tokens.copy()
793 local_tts_offset = tts_offset
794 local_this_uuid = this_uuid
795
796 tts_input_queue.put((local_this_uuid, tokens_to_send, local_tts_offset, finalize))
797
798 # update tts offset for streaming tts
799 with tts_state_lock:
800 tts_offset += token_hop_len
801 if tts_offset >= max_tts_tokens:
802 tts_offset -= max_tts_tokens
803 cur_audio_tokens = cur_audio_tokens[max_tts_tokens:]
804 accumulate_tts_tokens += max_tts_tokens
805 if accumulate_tts_tokens >= MAX_TTS_HISTORY:
806 accumulate_tts_tokens = 0
807 tts_control_queue.put(('clear_cache', this_uuid))
808 tts_control_queue.put(('init_cache', this_uuid))
809
810 except Exception as e:
811 log("error", f"TTS sender thread error: {e}")
812 import traceback
813 traceback.print_exc()
814
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)"""

Callers

nothing calls this directly

Calls 2

logFunction · 0.85
putMethod · 0.80

Tested by

no test coverage detected