Skip to content

Commit 96a3555

Browse files
author
jiangtao
committed
语音发送新增同步机制
1 parent fb74fe2 commit 96a3555

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

core/connection.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,24 @@ def _priority_thread(self):
299299
self.logger.bind(tag=TAG).error(f"TTS 任务出错: {e}")
300300
continue
301301
if not self.client_abort:
302-
with self.lock: # 使用实例锁来确保顺序传输
303-
self.logger.bind(tag=TAG).info(f"发送TTS语音: {text}")
302+
with self.lock:
303+
#sleep_time = max(duration, 1 if len(text) <= 3 else len(text) * 0.2)
304+
# 使用实例锁来确保顺序传输
305+
self.logger.bind(tag=TAG).info(f"发送TTS语音: {text}, 时长:{duration}, sleep_time:{duration}")
304306
text = '';
305-
asyncio.run_coroutine_threadsafe(
306-
sendAudioMessage(self, opus_datas, duration, text), self.loop
307+
#asyncio.run_coroutine_threadsafe(
308+
# sendAudioMessage(self, opus_datas, duration, text), self.loop
309+
#)
310+
future = asyncio.run_coroutine_threadsafe(
311+
sendAudioMessage(self, opus_datas, duration, text),
312+
self.loop
307313
)
308-
sleep_time = 1 if len(text) <= 3 else len(text) * 0.7
309-
time.sleep(sleep_time) # 在每次发送后引入2秒的延迟
314+
# 等待异步操作完成
315+
future.result()
316+
# 等待一段时间,确保音频播放完成
317+
318+
time.sleep(duration)
319+
310320
#if self.tts.delete_audio_file and os.path.exists(tts_file):
311321
# os.remove(tts_file)
312322
except Exception as e:

core/handle/audioHandle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def startToChat(conn, text):
7878

7979
async def sendAudioMessage(conn, audios, duration, text):
8080
base_delay = conn.tts_duration
81-
base_delay = 1 if len(text) <= 3 else len(text) * 0.35
81+
#base_delay = 1 if len(text) <= 3 else len(text) * 0.35
8282
# 发送 tts.start
8383
if text == conn.tts_first_text:
8484
logger.bind(tag=TAG).info(f"发送第一段语音: {text}")

0 commit comments

Comments
 (0)