From 80c42818886975f4dd1683479f517b477845d5d7 Mon Sep 17 00:00:00 2001 From: binary-husky Date: Thu, 30 May 2024 14:27:18 +0000 Subject: [PATCH] TTS Default Enable --- Dockerfile | 11 ++++++----- shared_utils/fastapi_server.py | 13 ++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index d54ba1ec..2f1cd970 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,15 +12,16 @@ RUN echo '[global]' > /etc/pip.conf && \ echo 'trusted-host = mirrors.aliyun.com' >> /etc/pip.conf +# 语音输出功能(以下两行,第一行更换阿里源,第二行安装ffmpeg,都可以删除) +RUN UBUNTU_VERSION=$(awk -F= '/^VERSION_CODENAME=/{print $2}' /etc/os-release); echo "deb https://mirrors.aliyun.com/debian/ $UBUNTU_VERSION main non-free contrib" > /etc/apt/sources.list; apt-get update +RUN apt-get install ffmpeg -y + + # 进入工作路径(必要) WORKDIR /gpt -# TTS相关功能 -RUN apt update && apt install ffmpeg -y - - -# 安装大部分依赖,利用Docker缓存加速以后的构建 (以下三行,可以删除) +# 安装大部分依赖,利用Docker缓存加速以后的构建 (以下两行,可以删除) COPY requirements.txt ./ RUN pip3 install -r requirements.txt diff --git a/shared_utils/fastapi_server.py b/shared_utils/fastapi_server.py index 20c37f07..b30a5aaa 100644 --- a/shared_utils/fastapi_server.py +++ b/shared_utils/fastapi_server.py @@ -160,11 +160,14 @@ def start_app(app_block, CONCURRENT_COUNT, AUTHENTICATION, PORT, SSL_KEYFILE, SS temp_file_name = str(uuid.uuid4().hex) temp_file = os.path.join(temp_folder, f'{temp_file_name}.mp3') await tts.save(temp_file) - mp3_audio = AudioSegment.from_file(temp_file, format="mp3") - mp3_audio.export(temp_file, format="wav") - with open(temp_file, 'rb') as wav_file: t = wav_file.read() - os.remove(temp_file) - return Response(content=t) + try: + mp3_audio = AudioSegment.from_file(temp_file, format="mp3") + mp3_audio.export(temp_file, format="wav") + with open(temp_file, 'rb') as wav_file: t = wav_file.read() + os.remove(temp_file) + return Response(content=t) + except: + raise RuntimeError("ffmpeg未安装,无法处理EdgeTTS音频。安装方法见`https://github.com/jiaaro/pydub#getting-ffmpeg-set-up`") if TTS_TYPE == "LOCAL_SOVITS_API": # Forward the request to the target service TARGET_URL = get_conf("GPT_SOVITS_URL")