mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
update:优化
This commit is contained in:
parent
c9e969a971
commit
c066daf756
5 changed files with 20 additions and 653 deletions
|
|
@ -30,7 +30,7 @@ docker镜像已支持x86架构、arm64架构的CPU,支持在国产操作系统
|
||||||
|
|
||||||
## 3. 下载docker-compose.yaml
|
## 3. 下载docker-compose.yaml
|
||||||
|
|
||||||
用浏览器打开[这个链接](https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/docker-compose.yml)。
|
用浏览器打开[这个链接](../main/xiaozhi-server/docker-compose.yml)。
|
||||||
|
|
||||||
在页面的右侧找到名称为`RAW`按钮,在`RAW`按钮的旁边,找到下载的图标,点击下载按钮,下载`docker-compose.yml`文件。 把文件下载到你的
|
在页面的右侧找到名称为`RAW`按钮,在`RAW`按钮的旁边,找到下载的图标,点击下载按钮,下载`docker-compose.yml`文件。 把文件下载到你的
|
||||||
`项目目录`中。
|
`项目目录`中。
|
||||||
|
|
@ -39,7 +39,7 @@ docker镜像已支持x86架构、arm64架构的CPU,支持在国产操作系统
|
||||||
|
|
||||||
## 3. 下载配置文件
|
## 3. 下载配置文件
|
||||||
|
|
||||||
用浏览器打开[这个链接](https://github.com/xinnan-tech/xiaozhi-esp32-server/blob/main/config.yaml)。
|
用浏览器打开[这个链接](../main/xiaozhi-server/config.yaml)。
|
||||||
|
|
||||||
在页面的右侧找到名称为`RAW`按钮,在`RAW`按钮的旁边,找到下载的图标,点击下载按钮,下载`config.yaml`文件。 把文件下载到你的
|
在页面的右侧找到名称为`RAW`按钮,在`RAW`按钮的旁边,找到下载的图标,点击下载按钮,下载`config.yaml`文件。 把文件下载到你的
|
||||||
`项目目录`下面的`data`文件夹中,然后把`config.yaml`文件重命名为`.config.yaml`。
|
`项目目录`下面的`data`文件夹中,然后把`config.yaml`文件重命名为`.config.yaml`。
|
||||||
|
|
@ -193,14 +193,15 @@ conda install ffmpeg -y
|
||||||
打开完,找到页面中一个绿色的按钮,写着`Code`的按钮,点开它,然后你就看到`Download ZIP`的按钮。
|
打开完,找到页面中一个绿色的按钮,写着`Code`的按钮,点开它,然后你就看到`Download ZIP`的按钮。
|
||||||
|
|
||||||
点击它,下载本项目源码压缩包。下载到你电脑后,解压它,此时它的名字可能叫`xiaozhi-esp32-server-main`
|
点击它,下载本项目源码压缩包。下载到你电脑后,解压它,此时它的名字可能叫`xiaozhi-esp32-server-main`
|
||||||
你需要把它重命名成`xiaozhi-esp32-server`,好了请记住这个目录,我们暂且称它为`项目目录`。
|
你需要把它重命名成`xiaozhi-esp32-server`,在这个文件里,进入到`main`文件夹,再进入到`xiaozhi-server`,好了请记住这个目录`xiaozhi-server`,我们暂且称它为`项目目录`。
|
||||||
|
|
||||||
```
|
```
|
||||||
# 继续使用conda环境,进入到你的项目目录,执行以下命令
|
# 继续使用conda环境
|
||||||
conda activate xiaozhi-esp32-server
|
conda activate xiaozhi-esp32-server
|
||||||
|
# 进入到你的项目目录,记住由于你是用源码运行,main/xiaozhi-server是你的项目目录
|
||||||
|
cd main/xiaozhi-server
|
||||||
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
|
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
|
||||||
pip install poetry
|
pip install -r requirements.txt
|
||||||
poetry install --no-root
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3.下载语音识别模型文件
|
## 3.下载语音识别模型文件
|
||||||
|
|
@ -217,22 +218,14 @@ poetry install --no-root
|
||||||
|
|
||||||
## 5.运行项目
|
## 5.运行项目
|
||||||
|
|
||||||
如果您想启动8000端口,接收esp32的语音服务
|
|
||||||
```
|
```
|
||||||
# 确保在本项目的根目录下执行
|
# 确保在本项目目录下执行
|
||||||
conda activate xiaozhi-esp32-server
|
conda activate xiaozhi-esp32-server
|
||||||
poetry run python app.py
|
python app.py
|
||||||
```
|
```
|
||||||
这时,你就要留意日志信息,可以根据这个教程,判断是否成功了。[跳转到运行状态确认](#运行状态确认)
|
这时,你就要留意日志信息,可以根据这个教程,判断是否成功了。[跳转到运行状态确认](#运行状态确认)
|
||||||
|
|
||||||
|
|
||||||
如果您想启动8002端口服务,启动管理后台
|
|
||||||
```
|
|
||||||
# 确保在本项目的根目录下执行
|
|
||||||
conda activate xiaozhi-esp32-server
|
|
||||||
poetry run uvicorn web.app:app --host 0.0.0.0 --port 8888 --reload
|
|
||||||
```
|
|
||||||
|
|
||||||
# 汇总
|
# 汇总
|
||||||
|
|
||||||
## 配置项目
|
## 配置项目
|
||||||
|
|
|
||||||
|
|
@ -9,251 +9,18 @@ import time
|
||||||
from core.handle.sendAudioHandle import send_stt_message
|
from core.handle.sendAudioHandle import send_stt_message
|
||||||
from core.utils import p3
|
from core.utils import p3
|
||||||
|
|
||||||
import urllib.request
|
|
||||||
import urllib.parse
|
|
||||||
urllib.request.socket.setdefaulttimeout(10)
|
|
||||||
import requests
|
|
||||||
import io
|
|
||||||
from threading import Thread, Event
|
|
||||||
from queue import Queue
|
|
||||||
import struct
|
|
||||||
from pydub import AudioSegment
|
|
||||||
import miniaudio
|
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
import opuslib_next
|
|
||||||
|
|
||||||
TAG = __name__
|
TAG = __name__
|
||||||
logger = setup_logging()
|
logger = setup_logging()
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_song_name(text):
|
||||||
class CustomIceCastClient(miniaudio.IceCastClient):
|
"""从用户输入中提取歌名"""
|
||||||
def read(self, num_bytes: int) -> bytes:
|
for keyword in ["听", "播放", "放", "唱"]:
|
||||||
"""Read a chunk of data from the stream."""
|
if keyword in text:
|
||||||
while len(self._buffer) < num_bytes:
|
parts = text.split(keyword)
|
||||||
time.sleep(0.1)
|
if len(parts) > 1:
|
||||||
if self._stop_stream:
|
return parts[1].strip()
|
||||||
raise ValueError("Steam stoped")
|
return None
|
||||||
with self._buffer_lock:
|
|
||||||
chunk = self._buffer[:num_bytes]
|
|
||||||
self._buffer = self._buffer[num_bytes:]
|
|
||||||
return chunk
|
|
||||||
|
|
||||||
|
|
||||||
class OpusStreamConverter:
|
|
||||||
@staticmethod
|
|
||||||
def search_mp3(keywords):
|
|
||||||
try:
|
|
||||||
encoded_keywords = urllib.parse.quote(keywords)
|
|
||||||
search_url = f"https://www.kumeiwp.com/index/search/data?page=1&limit=15&word={encoded_keywords}&scope=all"
|
|
||||||
|
|
||||||
logger.bind(tag=TAG).debug(f"Searching {keywords} {search_url}")
|
|
||||||
response = requests.get(search_url)
|
|
||||||
response.raise_for_status()
|
|
||||||
|
|
||||||
data = response.json()
|
|
||||||
if 'data' in data and len(data['data']) > 0:
|
|
||||||
for item in data['data']:
|
|
||||||
if 'file_id' in item and 'title' in item:
|
|
||||||
file_id = item['file_id']
|
|
||||||
import re
|
|
||||||
title = item['title']
|
|
||||||
if title.startswith('<img src=\"static/images/gs/mp3.gif\"'):
|
|
||||||
logger.bind(tag=TAG).debug(f'Found file_id: {file_id}')
|
|
||||||
mp3_title = keywords
|
|
||||||
title_pattern = r'title="([^"]*)"'
|
|
||||||
title_match = re.search(title_pattern, title)
|
|
||||||
if title_match:
|
|
||||||
mp3_title = title_match.group(1)
|
|
||||||
blacklisted_keywords = ["伴奏", "试听"]
|
|
||||||
if any(blacklisted in mp3_title for blacklisted in blacklisted_keywords):
|
|
||||||
continue
|
|
||||||
# Get the actual MP3 URL from the file page
|
|
||||||
file_url = f"https://www.kumeiwp.com/file/{file_id}.html"
|
|
||||||
file_response = requests.get(file_url)
|
|
||||||
file_response.raise_for_status()
|
|
||||||
|
|
||||||
# Find the source tag and extract the MP3 URL
|
|
||||||
source_pattern = r'<source src="([^"]*\.mp3)"'
|
|
||||||
sourc_ematch = re.search(source_pattern, file_response.text)
|
|
||||||
if sourc_ematch:
|
|
||||||
mp3_url = sourc_ematch.group(1)
|
|
||||||
logger.bind(tag=TAG).debug(f'Found MP3 URL: {mp3_url}')
|
|
||||||
return mp3_url, mp3_title
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).debug(f"Search error: {e}")
|
|
||||||
return None, None
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.buffer = Queue()
|
|
||||||
self.is_streaming = True
|
|
||||||
self.decoder = None
|
|
||||||
self.encoder = None
|
|
||||||
self.sample_rate = None
|
|
||||||
self.channels = None
|
|
||||||
self.frame_size = None
|
|
||||||
self.last_frame_time = None
|
|
||||||
self.timeout_event = Event()
|
|
||||||
self.client = None
|
|
||||||
self.stream = None
|
|
||||||
|
|
||||||
def check_timeout(self):
|
|
||||||
while not self.timeout_event.is_set():
|
|
||||||
if self.last_frame_time and time.time() - self.last_frame_time > 5:
|
|
||||||
logger.bind(tag=TAG).debug("No new frames for 5 seconds, closing stream")
|
|
||||||
self.buffer.put(None)
|
|
||||||
if self.client:
|
|
||||||
self.client.close()
|
|
||||||
break
|
|
||||||
time.sleep(0.1)
|
|
||||||
logger.bind(tag=TAG).debug("check_timeout thread ended")
|
|
||||||
#time.sleep(0.1)
|
|
||||||
#logger.bind(tag=TAG).debug_all_threads_stack()
|
|
||||||
|
|
||||||
def stream_reader(self, url):
|
|
||||||
try:
|
|
||||||
logger.bind(tag=TAG).debug(f"stream reader with {url}")
|
|
||||||
# Start timeout checker thread
|
|
||||||
timeout_thread = Thread(target=self.check_timeout)
|
|
||||||
timeout_thread.start()
|
|
||||||
self.last_frame_time = time.time()
|
|
||||||
|
|
||||||
self.client = CustomIceCastClient(url)
|
|
||||||
logger.bind(tag=TAG).debug("stream client created")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.stream = miniaudio.stream_any(
|
|
||||||
source=self.client,
|
|
||||||
source_format=miniaudio.FileFormat.MP3,
|
|
||||||
output_format=miniaudio.SampleFormat.SIGNED16,
|
|
||||||
nchannels=1,
|
|
||||||
sample_rate=16000,
|
|
||||||
frames_to_read=960
|
|
||||||
)
|
|
||||||
logger.bind(tag=TAG).debug("stream started")
|
|
||||||
frame_counter = 0
|
|
||||||
last_frame_len = 0
|
|
||||||
|
|
||||||
for frames in self.stream:
|
|
||||||
self.last_frame_time = time.time()
|
|
||||||
if not len(frames):
|
|
||||||
logger.bind(tag=TAG).debug("Empty frame detected, stream might have ended")
|
|
||||||
break
|
|
||||||
|
|
||||||
if frame_counter == 0:
|
|
||||||
self.initialize_encoder(frames)
|
|
||||||
logger.bind(tag=TAG).debug(f"Sample Rate: {self.sample_rate}")
|
|
||||||
logger.bind(tag=TAG).debug(f"Channels: {self.channels}")
|
|
||||||
logger.bind(tag=TAG).debug(f"Frame Size: {self.frame_size}")
|
|
||||||
|
|
||||||
if not self.is_streaming:
|
|
||||||
logger.bind(tag=TAG).debug("Streaming stopped by user")
|
|
||||||
break
|
|
||||||
|
|
||||||
# Check for stream errors or interruptions
|
|
||||||
if last_frame_len and len(frames) != last_frame_len:
|
|
||||||
logger.bind(tag=TAG).debug(f"Frame size changed: {last_frame_len} -> {len(frames)}")
|
|
||||||
|
|
||||||
last_frame_len = len(frames)
|
|
||||||
frame_counter += 1
|
|
||||||
self.buffer.put(frames.tobytes())
|
|
||||||
|
|
||||||
logger.bind(tag=TAG).debug(f"Stream ended after {frame_counter} frames")
|
|
||||||
self.buffer.put(None)
|
|
||||||
|
|
||||||
except ConnectionError as e:
|
|
||||||
logger.bind(tag=TAG).debug(f"Connection error: {e}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).debug(f"Error in stream reader: {e}")
|
|
||||||
finally:
|
|
||||||
logger.bind(tag=TAG).debug(f"Stream closed")
|
|
||||||
self.timeout_event.set()
|
|
||||||
try:
|
|
||||||
self.buffer.put(None)
|
|
||||||
self.client.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def initialize_encoder(self, first_frames):
|
|
||||||
self.sample_rate = 16000
|
|
||||||
self.channels = 1
|
|
||||||
self.frame_size = 960
|
|
||||||
|
|
||||||
self.encoder = opuslib_next.Encoder(
|
|
||||||
self.sample_rate,
|
|
||||||
self.channels,
|
|
||||||
opuslib_next.APPLICATION_AUDIO
|
|
||||||
)
|
|
||||||
|
|
||||||
def convert(self, url, output_file):
|
|
||||||
stream_thread = Thread(target=self.stream_reader, args=(url,))
|
|
||||||
stream_thread.start()
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(output_file, 'wb') as opus_file:
|
|
||||||
while True:
|
|
||||||
pcm_frame = self.buffer.get()
|
|
||||||
if pcm_frame is None:
|
|
||||||
break
|
|
||||||
|
|
||||||
# Encode PCM to Opus
|
|
||||||
if self.encoder:
|
|
||||||
opus_frame = self.encoder.encode(pcm_frame, self.frame_size)
|
|
||||||
frame_length = len(opus_frame)
|
|
||||||
opus_file.write(struct.pack('<H', frame_length))
|
|
||||||
opus_file.write(opus_frame)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).debug(f"Error during conversion: {e}")
|
|
||||||
finally:
|
|
||||||
logger.bind(tag=TAG).debug("Conversion stoping")
|
|
||||||
self.is_streaming = False
|
|
||||||
stream_thread.join()
|
|
||||||
|
|
||||||
def stream_player(self, url, conn, selected_music, stream_thread):
|
|
||||||
try:
|
|
||||||
opus_packets = []
|
|
||||||
started = False
|
|
||||||
while True:
|
|
||||||
pcm_frame = self.buffer.get()
|
|
||||||
if pcm_frame is None:
|
|
||||||
##music ends
|
|
||||||
if len(opus_packets) > 0:
|
|
||||||
conn.audio_play_queue.put((opus_packets, selected_music + "[end]"))
|
|
||||||
break
|
|
||||||
|
|
||||||
# Encode PCM to Opus
|
|
||||||
if self.encoder:
|
|
||||||
opus_frame = self.encoder.encode(pcm_frame, self.frame_size)
|
|
||||||
opus_packets.append(opus_frame)
|
|
||||||
if len(opus_packets) >= 100:
|
|
||||||
if not started:
|
|
||||||
started = True
|
|
||||||
conn.audio_play_queue.put((opus_packets, selected_music + "[start]"))
|
|
||||||
else:
|
|
||||||
conn.audio_play_queue.put((opus_packets, selected_music))
|
|
||||||
opus_packets = []
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).debug(f"Error during streaming: {e}")
|
|
||||||
finally:
|
|
||||||
logger.bind(tag=TAG).debug("Stream stoping")
|
|
||||||
self.is_streaming = False
|
|
||||||
stream_thread.join()
|
|
||||||
logger.bind(tag=TAG).debug("Stream stoped")
|
|
||||||
|
|
||||||
def play(self, url, conn, selected_music):
|
|
||||||
stream_thread = Thread(target=self.stream_reader, args=(url,))
|
|
||||||
stream_thread.start()
|
|
||||||
|
|
||||||
playing_thread = Thread(target=self.stream_player, args=(url, conn, selected_music, stream_thread))
|
|
||||||
playing_thread.start()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _find_best_match(potential_song, music_files):
|
def _find_best_match(potential_song, music_files):
|
||||||
|
|
@ -326,7 +93,7 @@ class MusicHandler:
|
||||||
self.scan_time = time.time()
|
self.scan_time = time.time()
|
||||||
logger.bind(tag=TAG).debug(f"刷新的音乐文件: {self.music_files}")
|
logger.bind(tag=TAG).debug(f"刷新的音乐文件: {self.music_files}")
|
||||||
|
|
||||||
potential_song = self._extract_song_name(clean_text)
|
potential_song = _extract_song_name(clean_text)
|
||||||
if potential_song:
|
if potential_song:
|
||||||
best_match = _find_best_match(potential_song, self.music_files)
|
best_match = _find_best_match(potential_song, self.music_files)
|
||||||
if best_match:
|
if best_match:
|
||||||
|
|
@ -336,24 +103,11 @@ class MusicHandler:
|
||||||
|
|
||||||
# 检查是否是通用播放音乐命令
|
# 检查是否是通用播放音乐命令
|
||||||
if any(cmd in clean_text for cmd in self.music_related_keywords):
|
if any(cmd in clean_text for cmd in self.music_related_keywords):
|
||||||
potential_song = self._extract_song_name(clean_text)
|
await self.play_local_music(conn)
|
||||||
if potential_song:
|
|
||||||
await self.play_remote_music(conn, potential_song)
|
|
||||||
else:
|
|
||||||
await self.play_local_music(conn)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _extract_song_name(self, text):
|
|
||||||
"""从用户输入中提取歌名"""
|
|
||||||
for keyword in self.music_related_keywords + ["听", "播放", "放", "唱"]:
|
|
||||||
if keyword in text:
|
|
||||||
parts = text.split(keyword)
|
|
||||||
if len(parts) > 1:
|
|
||||||
return parts[1].strip()
|
|
||||||
return None
|
|
||||||
|
|
||||||
async def play_local_music(self, conn, specific_file=None):
|
async def play_local_music(self, conn, specific_file=None):
|
||||||
"""播放本地音乐文件"""
|
"""播放本地音乐文件"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -383,7 +137,7 @@ class MusicHandler:
|
||||||
if not os.path.exists(music_path):
|
if not os.path.exists(music_path):
|
||||||
logger.bind(tag=TAG).error(f"选定的音乐文件不存在: {music_path}")
|
logger.bind(tag=TAG).error(f"选定的音乐文件不存在: {music_path}")
|
||||||
return
|
return
|
||||||
text = f"正在本地播放{selected_music}"
|
text = f"正在播放{selected_music}"
|
||||||
await send_stt_message(conn, text)
|
await send_stt_message(conn, text)
|
||||||
conn.tts_first_text_index = 0
|
conn.tts_first_text_index = 0
|
||||||
conn.tts_last_text_index = 0
|
conn.tts_last_text_index = 0
|
||||||
|
|
@ -394,26 +148,6 @@ class MusicHandler:
|
||||||
opus_packets, duration = conn.tts.wav_to_opus_data(music_path)
|
opus_packets, duration = conn.tts.wav_to_opus_data(music_path)
|
||||||
conn.audio_play_queue.put((opus_packets, selected_music, 0))
|
conn.audio_play_queue.put((opus_packets, selected_music, 0))
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.bind(tag=TAG).error(f"播放音乐失败: {str(e)}")
|
|
||||||
logger.bind(tag=TAG).error(f"详细错误: {traceback.format_exc()}")
|
|
||||||
|
|
||||||
async def play_remote_music(self, conn, potential_song):
|
|
||||||
try:
|
|
||||||
logger.bind(tag=TAG).debug(f"搜索并播放音乐: {potential_song}")
|
|
||||||
url, title = OpusStreamConverter.search_mp3(potential_song)
|
|
||||||
if url:
|
|
||||||
selected_music = title
|
|
||||||
text = f"正在搜索播放{selected_music}"
|
|
||||||
await send_stt_message(conn, text)
|
|
||||||
conn.tts_first_text = selected_music + "[start]"
|
|
||||||
conn.tts_last_text = selected_music + "[end]"
|
|
||||||
conn.llm_finish_task = True
|
|
||||||
converter = OpusStreamConverter()
|
|
||||||
logger.bind(tag=TAG).debug(f"Starting playing... {selected_music}")
|
|
||||||
converter.play(url, conn, selected_music)
|
|
||||||
else:
|
|
||||||
logger.bind(tag=TAG).debug("MP3 not found")
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.bind(tag=TAG).error(f"播放音乐失败: {str(e)}")
|
logger.bind(tag=TAG).error(f"播放音乐失败: {str(e)}")
|
||||||
logger.bind(tag=TAG).error(f"详细错误: {traceback.format_exc()}")
|
logger.bind(tag=TAG).error(f"详细错误: {traceback.format_exc()}")
|
||||||
|
|
@ -1,360 +0,0 @@
|
||||||
# 如果您是一名开发者,建议阅读以下内容。如果不是开发者,可以忽略这部分内容。
|
|
||||||
# 在开发中,在项目根目录创建data目录,将【config.yaml】复制一份,改成【.config.yaml】,放进data目录中
|
|
||||||
# 系统会优先读取【data/.config.yaml】文件的配置。
|
|
||||||
# 这样做,可以避免在提交代码的时候,错误地提交密钥信息,保护您的密钥安全。
|
|
||||||
|
|
||||||
# 服务器基础配置(Basic server configuration)
|
|
||||||
server:
|
|
||||||
# 服务器监听地址和端口(Server listening address and port)
|
|
||||||
ip: 0.0.0.0
|
|
||||||
port: 8000
|
|
||||||
# 认证配置
|
|
||||||
auth:
|
|
||||||
# 是否启用认证
|
|
||||||
enabled: false
|
|
||||||
# 设备的token,可以在编译固件的环节,写入你自己定义的token
|
|
||||||
# 固件上的token和以下的token如果能对应,才能连接本服务端
|
|
||||||
tokens:
|
|
||||||
- token: "your-token1" # 设备1的token
|
|
||||||
name: "your-device-name1" # 设备1标识
|
|
||||||
- token: "your-token2" # 设备2的token
|
|
||||||
name: "your-device-name2" # 设备2标识
|
|
||||||
# 可选:设备白名单,如果设置了白名单,那么白名单的机器无论是什么token都可以连接。
|
|
||||||
allowed_devices:
|
|
||||||
- "24:0A:C4:1D:3B:F0" # MAC地址列表
|
|
||||||
manager:
|
|
||||||
# 是否启用管理后台
|
|
||||||
# 目前这个模块还在开发中,建议:不要修改enabled选项
|
|
||||||
# 改了大概率报错,报错就会对这个项目失去信心,所以不建议修改
|
|
||||||
enabled: false
|
|
||||||
ip: 0.0.0.0
|
|
||||||
port: 8002
|
|
||||||
log:
|
|
||||||
# 设置控制台输出的日志格式,时间、日志级别、标签、消息
|
|
||||||
log_format: "<green>{time:YY-MM-DD HH:mm:ss}</green>[<light-blue>{extra[tag]}</light-blue>] - <level>{level}</level> - <light-green>{message}</light-green>"
|
|
||||||
# 设置日志文件输出的格式,时间、日志级别、标签、消息
|
|
||||||
log_format_simple: "{time:YYYY-MM-DD HH:mm:ss} - {name} - {level} - {extra[tag]} - {message}"
|
|
||||||
# 设置日志等级:INFO、DEBUG
|
|
||||||
log_level: INFO
|
|
||||||
# 设置日志路径
|
|
||||||
log_dir: tmp
|
|
||||||
# 设置日志文件
|
|
||||||
log_file: "server.log"
|
|
||||||
# 设置数据文件路径
|
|
||||||
data_dir: data
|
|
||||||
iot:
|
|
||||||
Speaker:
|
|
||||||
volume: 80
|
|
||||||
xiaozhi:
|
|
||||||
type: hello
|
|
||||||
version: 1
|
|
||||||
transport: websocket
|
|
||||||
audio_params:
|
|
||||||
format: opus
|
|
||||||
sample_rate: 16000
|
|
||||||
channels: 1
|
|
||||||
frame_duration: 60
|
|
||||||
prompt: |
|
|
||||||
你是一个叫小智/小志的台湾女孩,说话机车,声音好听,习惯简短表达,爱用网络梗。
|
|
||||||
请注意,要像一个人一样说话,请不要回复表情符号、代码、和xml标签。
|
|
||||||
当前时间是:{date_time},现在我正在和你进行语音聊天,我们开始吧。
|
|
||||||
如果用户希望结束对话,请在最后说“拜拜”或“再见”。
|
|
||||||
|
|
||||||
# 使用完声音文件后删除文件(Delete the sound file when you are done using it)
|
|
||||||
delete_audio: true
|
|
||||||
|
|
||||||
# 没有语音输入多久后断开连接(秒),默认2分钟,即120秒
|
|
||||||
close_connection_no_voice_time: 120
|
|
||||||
|
|
||||||
# 是否启用私有配置(Enable private configuration),启用后可以每个设备有不同的配置
|
|
||||||
# 目前这个模块还在开发中,建议:不要修改use_private_config选项
|
|
||||||
# 改了大概率报错,报错就会对这个项目失去信心,所以不建议修改
|
|
||||||
use_private_config: false
|
|
||||||
|
|
||||||
CMD_exit:
|
|
||||||
- "退出"
|
|
||||||
- "关闭"
|
|
||||||
|
|
||||||
# 具体处理时选择的模块(The module selected for specific processing)
|
|
||||||
selected_module:
|
|
||||||
ASR: FunASR
|
|
||||||
VAD: SileroVAD
|
|
||||||
# 将根据配置名称对应的type调用实际的LLM适配器
|
|
||||||
LLM: AliLLM
|
|
||||||
# TTS将根据配置名称对应的type调用实际的TTS适配器
|
|
||||||
TTS: TTS302AI
|
|
||||||
Memory: mem0ai
|
|
||||||
|
|
||||||
Memory:
|
|
||||||
mem0ai:
|
|
||||||
type: mem0ai
|
|
||||||
# https://app.mem0.ai/dashboard/api-keys,注册可获得试用credits
|
|
||||||
api_key: m0-U3TwP324tCYC1GjJA0t1W093Y1pPdwIoLbnx27X8
|
|
||||||
ASR:
|
|
||||||
FunASR:
|
|
||||||
type: fun_local
|
|
||||||
model_dir: models/SenseVoiceSmall
|
|
||||||
output_dir: tmp/
|
|
||||||
DoubaoASR:
|
|
||||||
# 服务地址 https://console.volcengine.com/speech/service/15
|
|
||||||
# 服务名称 一句话识别,需要点击开通,初次开通后有2万次额度
|
|
||||||
type: doubao
|
|
||||||
appid: 2632373421
|
|
||||||
access_token: 9B8nGVynfy3J9Hd5-jrjKuGRxXK8R32Z
|
|
||||||
cluster: volcengine_input_common
|
|
||||||
output_dir: tmp/
|
|
||||||
|
|
||||||
VAD:
|
|
||||||
SileroVAD:
|
|
||||||
threshold: 0.5
|
|
||||||
model_dir: models/snakers4_silero-vad
|
|
||||||
min_silence_duration_ms: 700 # 如果说话停顿比较长,可以把这个值设置大一些
|
|
||||||
|
|
||||||
LLM:
|
|
||||||
# 当前支持的type为openai、dify、ollama,可自行适配
|
|
||||||
AliLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: openai
|
|
||||||
# 可在这里找到你的 api_key https://bailian.console.aliyun.com/?apiKey=1#/api-key
|
|
||||||
base_url: https://dashscope.aliyuncs.com/compatible-mode/v1
|
|
||||||
model_name: qwen-turbo
|
|
||||||
api_key: sk-26dd86613b974adb948d78a7f2d867e4
|
|
||||||
DeepSeekLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: openai
|
|
||||||
# 可在这里找到你的api key https://platform.deepseek.com/
|
|
||||||
model_name: deepseek-reasoner
|
|
||||||
url: https://api.deepseek.com
|
|
||||||
api_key: sk-e038d66049fb4b96a7162ed1b20b3041
|
|
||||||
ChatGLMLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: openai
|
|
||||||
# glm-4-flash 是免费的,但是还是需要注册填写api_key的
|
|
||||||
# 可在这里找到你的api key https://bigmodel.cn/usercenter/proj-mgmt/apikeys
|
|
||||||
model_name: glm-4-flash
|
|
||||||
url: https://open.bigmodel.cn/api/paas/v4/
|
|
||||||
api_key: 49f04ea584d30a620327803a5845b778.C9Aklsr39vBOqxeR
|
|
||||||
OllamaLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: ollama
|
|
||||||
model_name: qwen2.5 # 使用的模型名称,需要预先使用ollama pull下载
|
|
||||||
base_url: http://localhost:11434 # Ollama服务地址
|
|
||||||
DifyLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: dify
|
|
||||||
# 建议使用本地部署的dify接口,国内部分区域访问dify公有云接口可能会受限
|
|
||||||
# 如果使用DifyLLM,配置文件里prompt(提示词)是无效的,需要在dify控制台设置提示词
|
|
||||||
base_url: https://api.dify.cn/v1
|
|
||||||
api_key: 你的DifyLLM web key
|
|
||||||
GeminiLLM:
|
|
||||||
type: gemini
|
|
||||||
# 谷歌Gemini API,需要先在Google Cloud控制台创建API密钥并获取api_key
|
|
||||||
# 若在中国境内使用,请遵守《生成式人工智能服务管理暂行办法》
|
|
||||||
# token申请地址: https://aistudio.google.com/apikey
|
|
||||||
# 若部署地无法访问接口,需要开启科学上网
|
|
||||||
api_key: 你的gemini web key
|
|
||||||
model_name: "gemini-1.5-pro" # gemini-1.5-pro 是免费的
|
|
||||||
CozeLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: coze
|
|
||||||
bot_id: 你的bot_id
|
|
||||||
user_id: 你的user_id
|
|
||||||
base_url: "https://api.coze.cn/open_api/v2/chat" # 服务地址
|
|
||||||
personal_access_token: 你的coze个人令牌
|
|
||||||
LMStudioLLM:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: openai
|
|
||||||
model_name: deepseek-r1-distill-llama-8b@q4_k_m # 使用的模型名称,需要预先在社区下载
|
|
||||||
url: http://localhost:1234/v1 # LM Studio服务地址
|
|
||||||
api_key: lm-studio # LM Studio服务的固定API Key
|
|
||||||
HomeAssistant:
|
|
||||||
# 定义LLM API类型
|
|
||||||
type: homeassistant
|
|
||||||
base_url: http://homeassistant.local:8123
|
|
||||||
agent_id: conversation.chatgpt
|
|
||||||
api_key: 你的home assistant api访问令牌
|
|
||||||
TTS:
|
|
||||||
# 当前支持的type为edge、doubao,可自行适配
|
|
||||||
EdgeTTS:
|
|
||||||
# 定义TTS API类型
|
|
||||||
type: edge
|
|
||||||
voice: zh-CN-XiaoxiaoNeural
|
|
||||||
output_file: tmp/
|
|
||||||
DoubaoTTS:
|
|
||||||
# 定义TTS API类型
|
|
||||||
type: doubao
|
|
||||||
# 火山引擎语音合成服务,需要先在火山引擎控制台创建应用并获取appid和access_token
|
|
||||||
# 山引擎语音一定要购买花钱,起步价30元,就有100并发了。如果用免费的只有2个并发,会经常报tts错误
|
|
||||||
# 购买服务后,购买免费的音色后,可能要等半小时左右,才能使用。
|
|
||||||
# 地址:https://console.volcengine.com/speech/service/8
|
|
||||||
api_url: https://openspeech.bytedance.com/api/v1/tts
|
|
||||||
voice: BV213_streaming
|
|
||||||
output_file: tmp/
|
|
||||||
appid: 2632373421
|
|
||||||
authorization: "Bearer;"
|
|
||||||
access_token: 9B8nGVynfy3J9Hd5-jrjKuGRxXK8R32Z
|
|
||||||
cluster: volcano_tts
|
|
||||||
TTS302AI:
|
|
||||||
# 默认使用湾湾小何语音
|
|
||||||
# 302AI语音合成服务,需要先在302平台创建账户充值,并获取登录信息
|
|
||||||
# 获取api_keyn路径:https://dash.302.ai/apis/list
|
|
||||||
# 价格,$35/百万字符。火山原版¥450元/百万字符。
|
|
||||||
type: doubao
|
|
||||||
api_url: https://api.302ai.cn/doubao/tts_hd
|
|
||||||
voice: "zh_female_wanwanxiaohe_moon_bigtts"
|
|
||||||
output_file: tmp/
|
|
||||||
authorization: "Bearer "
|
|
||||||
access_token: sk-q7dqFE21r57mrCwM7gKBlDdXCPAcCjw9eGD5XdHJhiNzCpZ2
|
|
||||||
CosyVoiceSiliconflow:
|
|
||||||
type: siliconflow
|
|
||||||
# 硅基流动TTS
|
|
||||||
# token申请地址 https://cloud.siliconflow.cn/account/ak
|
|
||||||
model: FunAudioLLM/CosyVoice2-0.5B
|
|
||||||
voice: FunAudioLLM/CosyVoice2-0.5B:alex
|
|
||||||
output_file: tmp/
|
|
||||||
access_token: sk-iyqvupoqdouokqdqvulgvdsqiwmoxmostuxonntmvpnhxyej
|
|
||||||
response_format: wav
|
|
||||||
CozeCnTTS:
|
|
||||||
type: cozecn
|
|
||||||
# COZECN TTS
|
|
||||||
# token申请地址 https://www.coze.cn/open/oauth/pats
|
|
||||||
voice: 7426720361733046281
|
|
||||||
output_file: tmp/
|
|
||||||
access_token: 你的coze web key
|
|
||||||
response_format: wav
|
|
||||||
FishSpeech:
|
|
||||||
# 定义TTS API类型
|
|
||||||
#启动tts方法:
|
|
||||||
#python -m tools.api_server
|
|
||||||
#--listen 0.0.0.0:8080
|
|
||||||
#--llama-checkpoint-path "checkpoints/fish-speech-1.5"
|
|
||||||
#--decoder-checkpoint-path "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth"
|
|
||||||
#--decoder-config-name firefly_gan_vq
|
|
||||||
#--compile
|
|
||||||
type: fishspeech
|
|
||||||
output_file: tmp/
|
|
||||||
response_format: wav
|
|
||||||
reference_id: null
|
|
||||||
reference_audio: [ "/tmp/test.wav", ]
|
|
||||||
reference_text: [ "你弄来这些吟词宴曲来看,还是这些混话来欺负我。", ]
|
|
||||||
normalize: true
|
|
||||||
max_new_tokens: 1024
|
|
||||||
chunk_length: 200
|
|
||||||
top_p: 0.7
|
|
||||||
repetition_penalty: 1.2
|
|
||||||
temperature: 0.7
|
|
||||||
streaming: false
|
|
||||||
use_memory_cache: "on"
|
|
||||||
seed: null
|
|
||||||
channels: 1
|
|
||||||
rate: 44100
|
|
||||||
api_key: "你的api_key"
|
|
||||||
api_url: "http://127.0.0.1:8080/v1/tts"
|
|
||||||
GPT_SOVITS_V2:
|
|
||||||
# 定义TTS API类型
|
|
||||||
#启动tts方法:
|
|
||||||
#python api_v2.py -a 127.0.0.1 -p 9880 -c GPT_SoVITS/configs/caixukun.yaml
|
|
||||||
type: gpt_sovits_v2
|
|
||||||
url: "http://127.0.0.1:9880/tts"
|
|
||||||
output_file: tmp/
|
|
||||||
text_lang: "auto"
|
|
||||||
ref_audio_path: "caixukun.wav"
|
|
||||||
prompt_text: ""
|
|
||||||
prompt_lang: "zh"
|
|
||||||
top_k: 5
|
|
||||||
top_p: 1
|
|
||||||
temperature: 1
|
|
||||||
text_split_method: "cut0"
|
|
||||||
batch_size: 1
|
|
||||||
batch_threshold: 0.75
|
|
||||||
split_bucket: true
|
|
||||||
return_fragment: false
|
|
||||||
speed_factor: 1.0
|
|
||||||
streaming_mode: false
|
|
||||||
seed: -1
|
|
||||||
parallel_infer: true
|
|
||||||
repetition_penalty: 1.35
|
|
||||||
aux_ref_audio_paths: [ ]
|
|
||||||
MinimaxTTS:
|
|
||||||
# Minimax语音合成服务,需要先在minimax平台创建账户充值,并获取登录信息
|
|
||||||
# 平台地址:https://platform.minimaxi.com/
|
|
||||||
# 充值地址:https://platform.minimaxi.com/user-center/payment/balance
|
|
||||||
# group_id地址:https://platform.minimaxi.com/user-center/basic-information
|
|
||||||
# api_key地址:https://platform.minimaxi.com/user-center/basic-information/interface-key
|
|
||||||
# 定义TTS API类型
|
|
||||||
type: minimax
|
|
||||||
output_file: tmp/
|
|
||||||
group_id: 你的minimax平台groupID
|
|
||||||
api_key: 你的minimax平台接口密钥
|
|
||||||
model: "speech-01-turbo"
|
|
||||||
# 此处设置将优先于voice_setting中voice_id的设置;如都不设置,默认为 female-shaonv
|
|
||||||
voice_id: "female-shaonv"
|
|
||||||
# 以下可不用设置,使用默认设置
|
|
||||||
# voice_setting:
|
|
||||||
# voice_id: "male-qn-qingse"
|
|
||||||
# speed: 1
|
|
||||||
# vol: 1
|
|
||||||
# pitch: 0
|
|
||||||
# emotion: "happy"
|
|
||||||
# pronunciation_dict:
|
|
||||||
# tone:
|
|
||||||
# - "处理/(chu3)(li3)"
|
|
||||||
# - "危险/dangerous"
|
|
||||||
# audio_setting:
|
|
||||||
# sample_rate: 32000
|
|
||||||
# bitrate: 128000
|
|
||||||
# format: "mp3"
|
|
||||||
# channel: 1
|
|
||||||
# timber_weights:
|
|
||||||
# -
|
|
||||||
# voice_id: male-qn-qingse
|
|
||||||
# weight: 1
|
|
||||||
# -
|
|
||||||
# voice_id: female-shaonv
|
|
||||||
# weight: 1
|
|
||||||
# language_boost: auto
|
|
||||||
AliyunTTS:
|
|
||||||
# 阿里云智能语音交互服务,需要先在阿里云平台开通服务,然后获取验证信息
|
|
||||||
# 平台地址:https://nls-portal.console.aliyun.com/
|
|
||||||
# appkey地址:https://nls-portal.console.aliyun.com/applist
|
|
||||||
# token地址:https://nls-portal.console.aliyun.com/overview
|
|
||||||
# 定义TTS API类型
|
|
||||||
type: aliyun
|
|
||||||
output_file: tmp/
|
|
||||||
appkey: 你的阿里云智能语音交互服务项目Appkey
|
|
||||||
token: 你的阿里云智能语音交互服务AccessToken
|
|
||||||
voice: xiaoyun
|
|
||||||
# 以下可不用设置,使用默认设置
|
|
||||||
# format: wav
|
|
||||||
# sample_rate: 16000
|
|
||||||
# volume: 50
|
|
||||||
# speech_rate: 0
|
|
||||||
# pitch_rate: 0
|
|
||||||
# 模块测试配置
|
|
||||||
module_test:
|
|
||||||
test_sentences: # 自定义测试语句
|
|
||||||
- "你好,请介绍一下你自己"
|
|
||||||
- "What's the weather like today?"
|
|
||||||
- "请用100字概括量子计算的基本原理和应用前景"
|
|
||||||
|
|
||||||
# 本地音乐播放配置
|
|
||||||
# 本地音乐播放配置
|
|
||||||
music:
|
|
||||||
music_commands:
|
|
||||||
- "来一首歌"
|
|
||||||
- "唱一首歌"
|
|
||||||
- "播放音乐"
|
|
||||||
- "来点音乐"
|
|
||||||
- "背景音乐"
|
|
||||||
- "放首歌"
|
|
||||||
- "播放歌曲"
|
|
||||||
- "来点背景音乐"
|
|
||||||
- "我想听歌"
|
|
||||||
- "我要听歌"
|
|
||||||
- "放点音乐"
|
|
||||||
music_dir: "./music" # 音乐文件存放路径,将从该目录及子目录下搜索音乐文件
|
|
||||||
music_ext: # 音乐文件类型,p3格式效率最高
|
|
||||||
- ".mp3"
|
|
||||||
- ".wav"
|
|
||||||
- ".p3"
|
|
||||||
refresh_time: 300 # 刷新音乐列表的时间间隔,单位为秒
|
|
||||||
Loading…
Reference in a new issue