mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 18:23:59 +08:00
Merge pull request #2114 from xinnan-tech/paddlespeech
update:更新paddlespeechtts供应器
This commit is contained in:
@@ -75,7 +75,7 @@ TTS:
|
|||||||
sample_rate: 24000 # 采样率 [websocket默认24000,http默认0 自动选择]
|
sample_rate: 24000 # 采样率 [websocket默认24000,http默认0 自动选择]
|
||||||
speed: 1.0 # 语速,1.0 表示正常语速,>1 表示加快,<1 表示减慢
|
speed: 1.0 # 语速,1.0 表示正常语速,>1 表示加快,<1 表示减慢
|
||||||
volume: 1.0 # 音量,1.0 表示正常音量,>1 表示增大,<1 表示减小
|
volume: 1.0 # 音量,1.0 表示正常音量,>1 表示增大,<1 表示减小
|
||||||
save_path: ./streaming_tts.wav # 服务器生成的语音文件保存路径
|
save_path: # 保存路径
|
||||||
```
|
```
|
||||||
### 3.启动xiaozhi服务
|
### 3.启动xiaozhi服务
|
||||||
```py
|
```py
|
||||||
|
|||||||
@@ -895,7 +895,7 @@ TTS:
|
|||||||
sample_rate: 24000 # 采样率 [websocket默认24000,http默认0 自动选择]
|
sample_rate: 24000 # 采样率 [websocket默认24000,http默认0 自动选择]
|
||||||
speed: 1.0 # 语速,1.0 表示正常语速,>1 表示加快,<1 表示减慢
|
speed: 1.0 # 语速,1.0 表示正常语速,>1 表示加快,<1 表示减慢
|
||||||
volume: 1.0 # 音量,1.0 表示正常音量,>1 表示增大,<1 表示减小
|
volume: 1.0 # 音量,1.0 表示正常音量,>1 表示增大,<1 表示减小
|
||||||
save_path: ./streaming_tts.wav # 服务器生成的语音文件保存路径
|
save_path: # 保存路径
|
||||||
IndexStreamTTS:
|
IndexStreamTTS:
|
||||||
# 基于Index-TTS-vLLM项目的TTS接口服务
|
# 基于Index-TTS-vLLM项目的TTS接口服务
|
||||||
# 参照教程:https://github.com/Ksuriuri/index-tts-vllm/blob/master/README.md
|
# 参照教程:https://github.com/Ksuriuri/index-tts-vllm/blob/master/README.md
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import wave
|
|||||||
import websockets
|
import websockets
|
||||||
from core.providers.tts.base import TTSProviderBase
|
from core.providers.tts.base import TTSProviderBase
|
||||||
from config.logger import setup_logging
|
from config.logger import setup_logging
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
@@ -18,6 +19,7 @@ class TTSProvider(TTSProviderBase):
|
|||||||
super().__init__(config, delete_audio_file)
|
super().__init__(config, delete_audio_file)
|
||||||
self.url = config.get("url", "ws://192.168.1.10:8092/paddlespeech/tts/streaming")
|
self.url = config.get("url", "ws://192.168.1.10:8092/paddlespeech/tts/streaming")
|
||||||
self.protocol = config.get("protocol", "websocket")
|
self.protocol = config.get("protocol", "websocket")
|
||||||
|
|
||||||
if config.get("private_voice"):
|
if config.get("private_voice"):
|
||||||
self.spk_id = int(config.get("private_voice"))
|
self.spk_id = int(config.get("private_voice"))
|
||||||
else:
|
else:
|
||||||
@@ -32,7 +34,21 @@ class TTSProvider(TTSProviderBase):
|
|||||||
volume = config.get("volume", 1.0)
|
volume = config.get("volume", 1.0)
|
||||||
self.volume = float(volume) if volume else 1.0
|
self.volume = float(volume) if volume else 1.0
|
||||||
|
|
||||||
self.save_path = config.get("save_path", "./streaming_tts.wav")
|
self.delete_audio_file = config.get("delete_audio", True)
|
||||||
|
if not self.delete_audio_file:
|
||||||
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
save_path = config.get("save_path")
|
||||||
|
if save_path:
|
||||||
|
if not save_path.endswith('.wav'):
|
||||||
|
save_path = f"{save_path}_{timestamp}.wav"
|
||||||
|
else:
|
||||||
|
other_path = save_path[:-4]
|
||||||
|
save_path = f"{other_path}_{timestamp}.wav"
|
||||||
|
self.save_path = save_path
|
||||||
|
else:
|
||||||
|
self.save_path = f"./streaming_tts_{timestamp}.wav"
|
||||||
|
else:
|
||||||
|
self.save_path = None
|
||||||
|
|
||||||
async def pcm_to_wav(self, pcm_data: bytes, sample_rate: int = 24000, num_channels: int = 1,
|
async def pcm_to_wav(self, pcm_data: bytes, sample_rate: int = 24000, num_channels: int = 1,
|
||||||
bits_per_sample: int = 16) -> bytes:
|
bits_per_sample: int = 16) -> bytes:
|
||||||
@@ -151,6 +167,12 @@ class TTSProvider(TTSProviderBase):
|
|||||||
# 接收结束响应避免服务抛出异常
|
# 接收结束响应避免服务抛出异常
|
||||||
await ws.recv()
|
await ws.recv()
|
||||||
|
|
||||||
|
# 根据配置决定是否保存文件
|
||||||
|
if not self.delete_audio_file and self.save_path:
|
||||||
|
with open(self.save_path, "wb") as f:
|
||||||
|
f.write(wav_data)
|
||||||
|
logger.bind(tag=TAG).info(f"音频文件已保存到: {self.save_path}")
|
||||||
|
|
||||||
# 返回或保存音频数据
|
# 返回或保存音频数据
|
||||||
if output_file:
|
if output_file:
|
||||||
with open(output_file, "wb") as file_to_save:
|
with open(output_file, "wb") as file_to_save:
|
||||||
|
|||||||
Reference in New Issue
Block a user