This commit is contained in:
seven 2025-03-25 22:20:05 +08:00
parent 6fa047c07d
commit be4f546a9c
2 changed files with 14 additions and 0 deletions

View file

@ -36,6 +36,8 @@ async def sendAudio(conn, audios):
if isinstance(audios,types.GeneratorType): if isinstance(audios,types.GeneratorType):
count = 0 count = 0
for opus_packet in audios: for opus_packet in audios:
if len(opus_packet) < 1:
continue
if count < 3: if count < 3:
await conn.websocket.send(opus_packet) await conn.websocket.send(opus_packet)
conn.logger.bind(tag=TAG).debug(f"预缓冲帧 {count}, 时间: {(time.perf_counter() - start_time) * 1000:.2f}ms") conn.logger.bind(tag=TAG).debug(f"预缓冲帧 {count}, 时间: {(time.perf_counter() - start_time) * 1000:.2f}ms")

View file

@ -111,5 +111,17 @@ class TTSProvider(TTSProviderBase):
opus_datas.append(opus_data) opus_datas.append(opus_data)
return opus_datas, duration return opus_datas, duration
if __name__ == "__main__":
config = {'access_token':'123',
'voice':'OUeAo1mhq6IBExi',
'response_format':'opus',
'sample_rate':16000
}
tts_provider = TTSProvider(config=config,delete_audio_file=True)
tts_provider.text_to_speak('你好呀,你是谁','asdf.txt')
data,dur = tts_provider.audio_to_opus_data('asdf.txt')
for x in data:
print(len(x))