From b2f3799fcabbb2ee9af9cef093887ea90a09f9d1 Mon Sep 17 00:00:00 2001 From: kejingfan Date: Sat, 13 Jul 2024 00:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/README.md b/README.md index e69de29..4a405d8 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,173 @@ +# 1. 什么是Mirror Chat? + +Mirror Chat是一个AI驱动的音频对话系统。该系统实现一个后端模型API:请求方输入语言选择(支持中/英)和音频,API返回AI生成的回答音频,该音频克隆了请求方音频的发音人音色。 + + + +# 2. 系统架构 + +架构图.drawio + + + +# 3. 安装方法 + +环境:Ubuntu 22.04,显存8G以上 + +各个组件以API的形式独立运行(可以运行在不同服务器中),可以在同一局域网中调用,也可以通过内网穿透的方式调用。 + +## 3.1. WeNet + +参考[WeNet的Github页面](https://github.com/wenet-e2e/wenet) + +1. 克隆仓库 + + 在MirrorChat目录下: + + ```sh + cd dependencies + git clone https://github.com/wenet-e2e/wenet.git + ``` + +2. 创建Conda环境 + + ```sh + conda create -n wenet python=3.10 + conda activate wenet + ``` + +3. 安装CUDA,建议12.1版本以上 + +4. 安装torch和torchaudio,以及其他依赖包 + + ```sh + pip install torch==2.2.2+cu121 torchaudio==2.2.2+cu121 -f https://download.pytorch.org/whl/torch_stable.html + pip install -r requirements.txt + pre-commit install # for clean and tidy code + ``` + +5. (可选)构建部署 + + ``` + # runtime build requires cmake 3.14 or above + cd runtime/libtorch + mkdir build && cd build && cmake -DGRAPH_TOOLS=ON .. && cmake --build . + ``` + +6. 运行 + + 在MirrorChat目录下: + + ```sh + cd api/wenet + bash run_wenet.sh + ``` + +## 3.2. xTTS + +参考[xTTS的Github页面](https://github.com/coqui-ai/TTS?tab=readme-ov-file) + +1. 克隆仓库 + + 在MirrorChat目录下: + + ```sh + cd dependencies + git clone https://github.com/coqui-ai/TTS + ``` + +2. 创建Conda环境 + + ```sh + conda create -n xtts python=3.10 + conda activate xtts + ``` + +3. 安装依赖包 + + ```sh + pip install TTS + pip install -e . + ``` + +4. 运行 + + 在MirrorChat目录下: + + ```sh + cd api/xtts + bash run_xtts.sh + ``` + +当显存充足时,可以编辑 `run_xtts.sh` 在不同端口开启多个服务,并在 `3.3. 问答TTS` 的 `main.py` 文件中对应修改调用接口,可以提高并行度,提高响应效率。 + +## 3.3. 问答TTS + +1. 将上述模型运行起来后,在MirrorChat目录下: + + ```sh + cd api/tts + ``` + +2. 创建ChatGPT API的配置文件 `chatgpt_api_config.py` + + ```sh + touch chatgpt_api_config.py + vim chatgpt_api_config.py + ``` + + 并将ChatGPT API的配置以以下形式写入(支持多个API,默认使用第1个API,当前面的API无法使用,会自动使用后面的API): + + ```python + chatgpt_apis = [ + { + 'url': "https://api.openai.com/v1/chat/completions", + 'key': "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + ] + ``` + +3. 运行 + + 在 `MirrorChat/api/tts` 目录下: + + ```sh + bash run_tts.sh + ``` + +## 3.4. 对外接口 + +进入 `MirrorChat/api/service` 目录,运行对外接口服务 + +```sh +cd api/service +bash run_service.sh +``` + +## 3.5. 调用方法 + +你可以使用类型下面python代码的方式调用该接口: + +```python +import requests + +def test_process_audio(api_url, audio_file_path, language): + url = f"{api_url}/process_audio" + files = {'audio': open(audio_file_path, 'rb')} + data = {'language': language} + response = requests.post(url, files=files, data=data) + + if response.status_code == 200: + output_audio_path = 'response_audio.wav' + with open(output_audio_path, 'wb') as f: + f.write(response.content) + print(f"Response audio saved to {output_audio_path}") + else: + print(f"Error: {response.status_code}") + print(response.json()) +``` + + + + +