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
74700da91d
commit
3856f78fa2
1 changed files with 36 additions and 31 deletions
|
|
@ -8,7 +8,6 @@ import os
|
|||
from pydub import AudioSegment
|
||||
import opuslib_next
|
||||
import numpy as np
|
||||
from collections import deque
|
||||
|
||||
class TTSProvider(TTSProviderBase):
|
||||
def __init__(self, config, delete_audio_file):
|
||||
|
|
@ -18,9 +17,9 @@ class TTSProvider(TTSProviderBase):
|
|||
self.response_format = config.get("response_format")
|
||||
self.sample_rate = config.get("sample_rate")
|
||||
self.instruct_text = config.get("instruct_text")
|
||||
self.stream_mode = config.get('stream_mode') # stream or double_stream
|
||||
self.host = "tts.linkerai.top"
|
||||
self.api_url = 'http://tts.linkerai.top:24003/tts'
|
||||
self.cache_queue = deque(maxlen=30)
|
||||
|
||||
def generate_filename(self, extension=".wav"):
|
||||
return os.path.join(self.output_file, f"tts-{datetime.now().date()}@{uuid.uuid4().hex}{extension}")
|
||||
|
|
@ -41,6 +40,7 @@ class TTSProvider(TTSProviderBase):
|
|||
}
|
||||
|
||||
with open(output_file,'w',encoding='utf-8') as f:
|
||||
f.write('http_post\n')
|
||||
f.write('%s\n'%(json.dumps(params,ensure_ascii=False)))
|
||||
f.write('%s'%(json.dumps(headers,ensure_ascii=False)))
|
||||
self.cache_queue.append(output_file)
|
||||
|
|
@ -57,16 +57,21 @@ class TTSProvider(TTSProviderBase):
|
|||
print(f"错误信息: {response.text}")
|
||||
|
||||
def audio_to_opus_data(self, audio_file_path):
|
||||
if audio_file_path in self.cache_queue:# os.path.exists('%s.linkerai'%audio_file_path):
|
||||
data = b''
|
||||
if os.path.exists('%s.linkerai'%audio_file_path):
|
||||
with open(audio_file_path,encoding='utf-8') as f:
|
||||
data = f.read(10)
|
||||
if data.startswith('http_post'):
|
||||
duration = 100
|
||||
code = []
|
||||
with open(audio_file_path,encoding='utf-8') as f:
|
||||
for line in f.readlines():
|
||||
code.append(json.loads(line.strip()))
|
||||
params = code[0]
|
||||
headers = code[1]
|
||||
return self.yield_data(params=params,headers=headers),duration
|
||||
else: # 兼容非流式音频播放
|
||||
|
||||
if not data.startswith('http_post'):# 兼容非流式音频播放
|
||||
f.seek(0)
|
||||
file_type = os.path.splitext(audio_file_path)[1]
|
||||
if file_type:
|
||||
file_type = file_type.lstrip('.')
|
||||
|
|
|
|||
Loading…
Reference in a new issue