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

Function tts_worker_process

web_demo/server/server.py:56–150  ·  view source on GitHub ↗

TTS independent process1, avoiding Python GIL Args: input_queue: (uuid, tokens_list, offset, finalize) output_queue: (uuid, audio_array) control_queue: ('init_cache', uuid) / ('clear_cache', uuid) / ('stop', None) tts_gpu: GPU device id for TTS model (de

(input_queue: MPQueue, output_queue: MPQueue, control_queue: MPQueue, tts_gpu: int = 1)

Source from the content-addressed store, hash-verified

54 print(f"[{level.upper()}] {message}")
55
56def tts_worker_process(input_queue: MPQueue, output_queue: MPQueue, control_queue: MPQueue, tts_gpu: int = 1):
57 """
58 TTS independent process1, avoiding Python GIL
59
60 Args:
61 input_queue: (uuid, tokens_list, offset, finalize)
62 output_queue: (uuid, audio_array)
63 control_queue: ('init_cache', uuid) / ('clear_cache', uuid) / ('stop', None)
64 tts_gpu: GPU device id for TTS model (default: 1)
65 """
66
67 log("info", f"[TTS Process] Starting TTS worker process on cuda:{tts_gpu}...")
68 torch.cuda.set_device(tts_gpu)
69 tts_device = torch.device(f"cuda:{tts_gpu}")
70
71 log("info", "[TTS Process] Loading TTS model...")
72 tts_model = get_audio_detokenizer()
73
74 tts_spk_emb_path = tts_model_config['spk_emb_path']
75 tts_spk_embedding = torch.load(tts_spk_emb_path)["中文女"]["embedding"]
76 tts_spk_embedding = tts_spk_embedding.to(tts_device)
77
78 log("info", "[TTS Process] TTS model loaded successfully")
79
80 running = True
81 while running:
82 try:
83 # check control queue
84 try:
85 while not control_queue.empty():
86 cmd, data = control_queue.get_nowait()
87 if cmd == 'init_cache':
88 uuid_str = data
89 tts_model.model.hift_cache_dict[uuid_str] = None
90 log("info", f"[TTS Process] Initialized cache for {uuid_str}")
91 elif cmd == 'clear_cache':
92 uuid_str = data
93 if uuid_str in tts_model.model.hift_cache_dict:
94 del tts_model.model.hift_cache_dict[uuid_str]
95 log("info", f"[TTS Process] Cleared cache for {uuid_str}")
96 elif cmd == 'stop':
97 running = False
98 log("info", "[TTS Process] Received stop command")
99 break
100 except:
101 pass
102
103 if not running:
104 break
105
106 try:
107 task = input_queue.get(timeout=0.1)
108 except:
109 continue
110
111 uuid_str, tokens_list, offset, finalize = task
112
113 queue_size = input_queue.qsize()

Callers

nothing calls this directly

Calls 4

get_audio_detokenizerFunction · 0.90
tts_infer_streamingFunction · 0.90
logFunction · 0.85
putMethod · 0.80

Tested by

no test coverage detected