mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
修正self错误
This commit is contained in:
@@ -482,8 +482,10 @@ class TTSProvider(TTSProviderBase):
|
||||
finally:
|
||||
self._monitor_task = None
|
||||
|
||||
def to_tts_stream(self, text: str, opus_handler=self.handle_opus) -> None:
|
||||
def to_tts_stream(self, text: str, opus_handler=None) -> None:
|
||||
"""非流式TTS处理,用于测试及保存音频文件的场景"""
|
||||
if opus_handler is None:
|
||||
opus_handler = self.handle_opus
|
||||
try:
|
||||
# 创建新的事件循环
|
||||
loop = asyncio.new_event_loop()
|
||||
|
||||
@@ -629,7 +629,7 @@ class TTSProvider(TTSProviderBase):
|
||||
def wav_to_opus_data_audio_raw_stream(self, raw_data_var, is_end=False, callback: Callable[[Any], Any]=None):
|
||||
return self.opus_encoder.encode_pcm_to_opus_stream(raw_data_var, is_end, callback=callback)
|
||||
|
||||
def to_tts_stream(self, text: str, opus_handler=self.handle_opus) -> None:
|
||||
def to_tts_stream(self, text: str, opus_handler=None) -> None:
|
||||
"""非流式生成音频数据,用于生成音频及测试场景
|
||||
|
||||
Args:
|
||||
@@ -639,6 +639,8 @@ class TTSProvider(TTSProviderBase):
|
||||
Returns:
|
||||
list: 音频数据列表
|
||||
"""
|
||||
if opus_handler is None:
|
||||
opus_handler = self.handle_opus
|
||||
try:
|
||||
# 创建事件循环
|
||||
loop = asyncio.new_event_loop()
|
||||
|
||||
@@ -233,15 +233,15 @@ class TTSProvider(TTSProviderBase):
|
||||
logger.bind(tag=TAG).error(f"TTS请求异常: {e}")
|
||||
self.tts_audio_queue.put((SentenceType.LAST, [], None))
|
||||
|
||||
def to_tts_stream(self, text: str) -> list:
|
||||
def to_tts_stream(self, text: str, opus_handler=None) -> list:
|
||||
"""非流式TTS处理,用于测试及保存音频文件的场景
|
||||
|
||||
Args:
|
||||
text: 要转换的文本
|
||||
|
||||
Returns:
|
||||
list: 返回opus编码后的音频数据列表
|
||||
opus_handler: opus数据处理方法
|
||||
"""
|
||||
if opus_handler is None:
|
||||
opus_handler = self.handle_opus
|
||||
start_time = time.time()
|
||||
text = MarkdownCleaner.clean_markdown(text)
|
||||
|
||||
@@ -291,14 +291,9 @@ class TTSProvider(TTSProviderBase):
|
||||
# 最后一帧可能不足,用0填充
|
||||
frame = frame + b"\x00" * (frame_bytes - len(frame))
|
||||
|
||||
opus = self.opus_encoder.encode_pcm_to_opus(
|
||||
frame, end_of_stream=(i + frame_bytes >= len(pcm_data))
|
||||
self.opus_encoder.encode_pcm_to_opus_stream(
|
||||
frame, end_of_stream=(i + frame_bytes >= len(pcm_data)), callback=opus_handler
|
||||
)
|
||||
if opus:
|
||||
opus_datas.extend(opus)
|
||||
|
||||
return opus_datas
|
||||
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).error(f"TTS请求异常: {e}")
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user