mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
add
This commit is contained in:
parent
5bbca56506
commit
4e4777ad66
3 changed files with 29 additions and 29 deletions
|
|
@ -556,13 +556,13 @@ class ConnectionHandler:
|
||||||
def _audio_play_priority_thread(self):
|
def _audio_play_priority_thread(self):
|
||||||
while not self.stop_event.is_set():
|
while not self.stop_event.is_set():
|
||||||
text = None
|
text = None
|
||||||
if 1:#try:
|
try:
|
||||||
opus_datas, text, text_index = self.audio_play_queue.get()
|
opus_datas, text, text_index = self.audio_play_queue.get()
|
||||||
future = asyncio.run_coroutine_threadsafe(sendAudioMessage(self, opus_datas, text, text_index),
|
future = asyncio.run_coroutine_threadsafe(sendAudioMessage(self, opus_datas, text, text_index),
|
||||||
self.loop)
|
self.loop)
|
||||||
future.result()
|
future.result()
|
||||||
# except Exception as e:
|
except Exception as e:
|
||||||
# self.logger.bind(tag=TAG).error(f"audio_play_priority priority_thread: {text} {e}")
|
self.logger.bind(tag=TAG).error(f"audio_play_priority priority_thread: {text} {e}")
|
||||||
|
|
||||||
def speak_and_play(self, text, text_index=0):
|
def speak_and_play(self, text, text_index=0):
|
||||||
if text is None or len(text) <= 0:
|
if text is None or len(text) <= 0:
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ async def sendAudioStream(conn, audios):
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
play_position = 0
|
play_position = 0
|
||||||
|
|
||||||
if isinstance(audios,types.GeneratorType):
|
# if isinstance(audios,types.GeneratorType):
|
||||||
# if 1:#inspect.isasyncgen(audios):
|
if inspect.isasyncgen(audios):
|
||||||
count = 0
|
count = 0
|
||||||
for opus_packet in audios:
|
async for opus_packet in audios:
|
||||||
if opus_packet.startswith(b'text:'):
|
if opus_packet.startswith(b'text:'):
|
||||||
await send_tts_message(conn, "sentence_start", opus_packet.replace(b'text:','').decode('utf-8'))
|
await send_tts_message(conn, "sentence_start", opus_packet.replace(b'text:','').decode('utf-8'))
|
||||||
continue
|
continue
|
||||||
|
|
@ -73,10 +73,10 @@ async def sendAudio(conn, audios):
|
||||||
start_time = time.perf_counter()
|
start_time = time.perf_counter()
|
||||||
play_position = 0
|
play_position = 0
|
||||||
|
|
||||||
if isinstance(audios,types.GeneratorType):
|
# if isinstance(audios,types.GeneratorType):
|
||||||
# if inspect.isasyncgen(audios):
|
if inspect.isasyncgen(audios):
|
||||||
count = 0
|
count = 0
|
||||||
for opus_packet in audios:
|
async for opus_packet in audios:
|
||||||
if len(opus_packet) < 1:
|
if len(opus_packet) < 1:
|
||||||
continue
|
continue
|
||||||
if count < 3:
|
if count < 3:
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class TTSProvider(TTSProviderBase):
|
||||||
"tts_text": text,
|
"tts_text": text,
|
||||||
"spk_id": self.voice,
|
"spk_id": self.voice,
|
||||||
"frame_durition": 60,
|
"frame_durition": 60,
|
||||||
"stream": True,
|
"stream": str(True).lower(),
|
||||||
"target_sr": self.sample_rate,
|
"target_sr": self.sample_rate,
|
||||||
"audio_format":"opus",
|
"audio_format":"opus",
|
||||||
"instruct_text":self.instruct_text
|
"instruct_text":self.instruct_text
|
||||||
|
|
@ -47,27 +47,27 @@ class TTSProvider(TTSProviderBase):
|
||||||
f.write('%s\n'%(json.dumps(params,ensure_ascii=False)))
|
f.write('%s\n'%(json.dumps(params,ensure_ascii=False)))
|
||||||
f.write('%s'%(json.dumps(headers,ensure_ascii=False)))
|
f.write('%s'%(json.dumps(headers,ensure_ascii=False)))
|
||||||
|
|
||||||
def yield_data(self,url,params,headers):
|
# def yield_data(self,url,params,headers):
|
||||||
response = requests.get(url=url, headers=headers, params=params, stream=True)
|
# response = requests.get(url=url, headers=headers, params=params, stream=True)
|
||||||
if response.status_code == 200:
|
# if response.status_code == 200:
|
||||||
for chunk in response.iter_content(chunk_size=None):
|
# for chunk in response.iter_content(chunk_size=None):
|
||||||
if chunk:
|
# if chunk:
|
||||||
print(len(chunk))
|
# print(len(chunk))
|
||||||
yield chunk
|
# yield chunk
|
||||||
else:
|
# else:
|
||||||
print(f"请求失败,状态码: {response.status_code}")
|
# print(f"请求失败,状态码: {response.status_code}")
|
||||||
print(f"错误信息: {response.text}")
|
# print(f"错误信息: {response.text}")
|
||||||
|
|
||||||
|
|
||||||
# async def yield_data(self,base_url:str='',params:dict={},headers:dict={}):
|
async def yield_data(self,base_url:str='',params:dict={},headers:dict={}):
|
||||||
# async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
# try:
|
try:
|
||||||
# async with session.get(base_url, params=params, headers=headers,timeout=10) as response:
|
async with session.get(base_url, params=params, headers=headers,timeout=10) as response:
|
||||||
# if response.status == 200:
|
if response.status == 200:
|
||||||
# async for r in response.content.iter_chunks():
|
async for r in response.content.iter_chunks():
|
||||||
# yield r[0]
|
yield r[0]
|
||||||
# except aiohttp.ClientError as e:
|
except aiohttp.ClientError as e:
|
||||||
# pass
|
pass
|
||||||
|
|
||||||
def double_stream(self,question:str='',device_id:str=''):
|
def double_stream(self,question:str='',device_id:str=''):
|
||||||
params = {
|
params = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue