@@ -127,8 +127,6 @@ def __init__(self, config, delete_audio_file):
127127
128128 # 专属tts设置
129129 self .message_id = ""
130- self .tts_text = ""
131- self .text_buffer = []
132130
133131 # 创建Opus编码器
134132 self .opus_encoder = opus_encoder_utils .OpusEncoderUtils (
@@ -229,7 +227,6 @@ def tts_text_priority_thread(self):
229227
230228 # aliyunStream独有的参数生成
231229 self .message_id = str (uuid .uuid4 ().hex )
232- self .text_buffer = []
233230
234231 logger .bind (tag = TAG ).info ("开始启动TTS会话..." )
235232 future = asyncio .run_coroutine_threadsafe (
@@ -250,7 +247,6 @@ def tts_text_priority_thread(self):
250247 logger .bind (tag = TAG ).debug (
251248 f"开始发送TTS文本: { message .content_detail } "
252249 )
253- self .text_buffer .append (message .content_detail )
254250 future = asyncio .run_coroutine_threadsafe (
255251 self .text_to_speak (message .content_detail , None ),
256252 loop = self .conn .loop ,
@@ -275,9 +271,6 @@ def tts_text_priority_thread(self):
275271 if message .sentence_type == SentenceType .LAST :
276272 try :
277273 logger .bind (tag = TAG ).info ("开始结束TTS会话..." )
278- self .tts_text = textUtils .get_string_no_punctuation_or_emoji (
279- "" .join (self .text_buffer ).replace ("\n " , "" )
280- )
281274 future = asyncio .run_coroutine_threadsafe (
282275 self .finish_session (self .conn .sentence_id ),
283276 loop = self .conn .loop ,
@@ -444,34 +437,35 @@ async def _start_monitor_tts_response(self):
444437 event_name = header .get ("name" )
445438 if event_name == "SynthesisStarted" :
446439 logger .bind (tag = TAG ).debug ("TTS合成已启动" )
447- elif event_name == "SentenceBegin" :
448- logger .bind (tag = TAG ).debug (
449- f"句子语音生成开始: { self .tts_text } "
450- )
451- opus_datas_cache = []
452440 self .tts_audio_queue .put (
453- (SentenceType .FIRST , [], self . tts_text )
441+ (SentenceType .FIRST , [], None )
454442 )
443+ elif event_name == "SentenceBegin" :
444+ opus_datas_cache = []
455445 elif event_name == "SentenceEnd" :
456- logger .bind (tag = TAG ).info (
457- f"句子语音生成成功: { self .tts_text } "
458- )
459446 if (
460447 not is_first_sentence
461448 or first_sentence_segment_count > 10
462449 ):
463450 # 发送缓存的数据
464- self .tts_audio_queue .put (
465- (SentenceType .MIDDLE , opus_datas_cache , None )
466- )
451+ if self .conn .tts_MessageText :
452+ logger .bind (tag = TAG ).info (
453+ f"句子语音生成成功: { self .conn .tts_MessageText } "
454+ )
455+ self .tts_audio_queue .put (
456+ (SentenceType .MIDDLE , opus_datas_cache , self .conn .tts_MessageText )
457+ )
458+ self .conn .tts_MessageText = None
459+ else :
460+ self .tts_audio_queue .put (
461+ (SentenceType .MIDDLE , opus_datas_cache , None )
462+ )
467463 # 第一句话结束后,将标志设置为False
468464 is_first_sentence = False
469465 elif event_name == "SynthesisCompleted" :
470466 logger .bind (tag = TAG ).debug (f"会话结束~~" )
471467 self ._process_before_stop_play_files ()
472468 session_finished = True
473- self .reuse_judgment = time .time ()
474- self .tts_text = ""
475469 break
476470 except json .JSONDecodeError :
477471 logger .bind (tag = TAG ).warning ("收到无效的JSON消息" )
0 commit comments