mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
add: tts stream 输出,fishspeech支持,其他还未实现
This commit is contained in:
parent
1854d9f500
commit
2b87ab2d00
5 changed files with 15 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -147,3 +147,4 @@ tmp
|
|||
.env.development
|
||||
docker-compose.yml
|
||||
web/vue/node_modules
|
||||
/asr-models/
|
||||
|
|
|
|||
|
|
@ -87,12 +87,12 @@ selected_module:
|
|||
# 将根据配置名称对应的type调用实际的LLM适配器
|
||||
LLM: ChatGLMLLM
|
||||
# TTS将根据配置名称对应的type调用实际的TTS适配器
|
||||
TTS: EdgeTTS
|
||||
TTS: FishSpeech
|
||||
|
||||
ASR:
|
||||
FunASR:
|
||||
type: fun_local
|
||||
model_dir: models/SenseVoiceSmall
|
||||
model_dir: asr-models/iic/SenseVoiceSmall
|
||||
output_dir: tmp/
|
||||
DoubaoASR:
|
||||
type: doubao
|
||||
|
|
@ -129,7 +129,7 @@ LLM:
|
|||
# 可在这里找到你的api key https://bigmodel.cn/usercenter/proj-mgmt/apikeys
|
||||
model_name: glm-4-flash
|
||||
url: https://open.bigmodel.cn/api/paas/v4/
|
||||
api_key: 51ff5fdb325c4fc899923d532148c2dd.FFuMryUTTnf9fKRf
|
||||
api_key: f04500d80a234c9085be2b4020dce25f.gnnnWr3BRLuqeDHr
|
||||
OllamaLLM:
|
||||
# 定义LLM API类型
|
||||
type: ollama
|
||||
|
|
@ -170,7 +170,7 @@ LLM:
|
|||
api_key: 你的home assistant api访问令牌
|
||||
|
||||
TTS_SET:
|
||||
TTS_STREAM: false #是否启动流响应 true/false,默认false
|
||||
TTS_STREAM: true #是否启动流响应 true/false,默认false
|
||||
MAX_WORKERS: 4 #并发请求tts的数量,这个调太大,本地tts会变慢
|
||||
|
||||
TTS:
|
||||
|
|
|
|||
|
|
@ -103,12 +103,12 @@ async def handleIotDescriptors(conn, descriptors):
|
|||
descriptor["methods"])
|
||||
conn.iot_descriptors[descriptor["name"]] = iot_descriptor
|
||||
|
||||
# 暂时从配置文件中设置音量,后期通过意图识别控制音量
|
||||
default_iot_volume = 100
|
||||
if "iot" in conn.config:
|
||||
default_iot_volume = conn.config["iot"]["Speaker"]["volume"]
|
||||
logger.bind(tag=TAG).info(f"服务端设置音量为{default_iot_volume}")
|
||||
await send_iot_conn(conn, "Speaker", "SetVolume", {"volume": default_iot_volume})
|
||||
# TODO 暂时从配置文件中设置音量,后期通过意图识别控制音量
|
||||
# default_iot_volume = 100
|
||||
# if "iot" in conn.config:
|
||||
# default_iot_volume = conn.config["iot"]["Speaker"]["volume"]
|
||||
# logger.bind(tag=TAG).info(f"服务端设置音量为{default_iot_volume}")
|
||||
# await send_iot_conn(conn, "Speaker", "SetVolume", {"volume": default_iot_volume})
|
||||
|
||||
|
||||
async def send_iot_conn(conn, name, method_name, parameters):
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ async def sendAudioMessageStream(conn, audios_queue, text, text_index=0):
|
|||
|
||||
# 初始化流控参数
|
||||
frame_duration = 60 # 毫秒
|
||||
start_time = time.perf_counter() # 使用高精度计时器
|
||||
start_time = time.time() # 使用高精度计时器
|
||||
play_position = 0 # 已播放的时长(毫秒)
|
||||
time_out_stop = False
|
||||
while True:
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ class TTSProvider(TTSProviderBase):
|
|||
audio.set_channels(1).set_frame_rate(16000)
|
||||
return audio
|
||||
|
||||
async def text_to_speak_stream(self, text, queue: queue.Queue,text_index=0):
|
||||
async def text_to_speak_stream(self, text, queue: queue.Queue, text_index=0):
|
||||
try:
|
||||
# Prepare reference data
|
||||
byte_audios = [audio_to_bytes(ref_audio) for ref_audio in self.reference_audio]
|
||||
|
|
@ -222,7 +222,7 @@ class TTSProvider(TTSProviderBase):
|
|||
if not audio_buff:
|
||||
audio_buff = audio
|
||||
else:
|
||||
audio_buff += audio
|
||||
audio_buff = audio_buff.append(audio, crossfade=10)
|
||||
if len(audio_buff.raw_data) % 1920 == 0:
|
||||
# 把 audio 转成 opus
|
||||
opus_datas, duration = self.wav_to_opus_data_audio(audio_buff)
|
||||
|
|
@ -238,7 +238,7 @@ class TTSProvider(TTSProviderBase):
|
|||
if not audio_buff:
|
||||
audio_buff = self._get_audio_from_tts(chunk_total)
|
||||
else:
|
||||
audio_buff += self._get_audio_from_tts(chunk_total)
|
||||
audio_buff = audio_buff.append(self._get_audio_from_tts(chunk_total), crossfade=10)
|
||||
# 把 audio 转成 opus
|
||||
opus_datas, duration = self.wav_to_opus_data_audio(audio_buff)
|
||||
queue.put({
|
||||
|
|
|
|||
Loading…
Reference in a new issue