Skip to content

SOTA Open Source TTS

环境隔离,一键安装/修补环境,一键启动 (#214)

Guanghua Lu9c606c0c3ad3
diff --git a/API_FLAGS.txt b/API_FLAGS.txt
new file mode 100644
index 0000000..0fcd3df
--- /dev/null
+++ b/API_FLAGS.txt
@@ -0,0 +1,6 @@
+# --api
+# --listen 0.0.0.0:8000 \
+# --llama-checkpoint-path "checkpoints/text2semantic-sft-medium-v1.1-4k.pth" \
+# --llama-config-name dual_ar_2_codebook_medium \
+# --decoder-checkpoint-path "checkpoints/vq-gan-group-fsq-2x1024.pth" \
+# --decoder-config-name vqgan_pretrain
diff --git a/run_cmd.bat b/run_cmd.bat
new file mode 100644
index 0000000..204af9a
--- /dev/null
+++ b/run_cmd.bat
@@ -0,0 +1,53 @@
+@echo off
+chcp 65001
+
+set no_proxy="127.0.0.1, 0.0.0.0, localhost"
+setlocal enabledelayedexpansion
+
+cd /D "%~dp0"
+
+set PATH="%PATH%";%SystemRoot%\system32
+
+:: 检查是否有特殊字符
+echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~\u4E00-\u9FFF ] " >nul && (
+ echo.
+ echo 当前路径中存在特殊字符,请使fish-speech的路径不含特殊字符后再运行。 && (
+ goto end
+ )
+)
+
+:: 解决跨驱动器安装问题
+set TMP=%CD%\fishenv
+set TEMP=%CD%\fishenv
+
+:: 取消激活已经激活的环境
+(call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
+
+:: 安装路径配置
+set CONDA_ROOT_PREFIX=%cd%\fishenv\conda
+set INSTALL_ENV_DIR=%cd%\fishenv\env
+
+:: 环境隔离
+set PYTHONNOUSERSITE=1
+set PYTHONPATH=
+set PYTHONHOME=
+set "CUDA_PATH=%INSTALL_ENV_DIR%"
+set "CUDA_HOME=%CUDA_PATH%"
+
+:: 激活环境
+call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%"
+:: 检查环境是否成功激活
+if errorlevel 1 (
+ echo.
+ echo 环境激活失败
+ goto end
+) else (
+ echo.
+ echo 环境激活成功
+)
+
+:: 进入cmd
+cmd /k "%*"
+
+:end
+pause
diff --git a/start.bat b/start.bat
index 9250553..46b08a5 100644
--- a/start.bat
+++ b/start.bat
@@ -1,12 +1,203 @@
@echo off
chcp 65001
-echo loading page...
-set PYTHONPATH=%~dp0
-set no_proxy="localhost, 127.0.0.1, 0.0.0.0"
+
+set no_proxy="127.0.0.1, 0.0.0.0, localhost"
+setlocal enabledelayedexpansion
+
+cd /D "%~dp0"
+
+set PATH="%PATH%";%SystemRoot%\system32
+
+:: 安装Miniconda
+:: 检查是否有特殊字符
+echo "%CD%"| findstr /R /C:"[!#\$%&()\*+,;<=>?@\[\]\^`{|}~\u4E00-\u9FFF ] " >nul && (
+ echo.
+ echo 当前路径中存在特殊字符,请使fish-speech的路径不含特殊字符后再运行。 && (
+ goto end
+ )
+)
+:: 解决跨驱动器安装问题
+set TMP=%CD%\fishenv
+set TEMP=%CD%\fishenv
+:: 取消激活已经激活的环境
+(call conda deactivate && call conda deactivate && call conda deactivate) 2>nul
+:: 安装路径配置
+set INSTALL_DIR=%cd%\fishenv
+set CONDA_ROOT_PREFIX=%cd%\fishenv\conda
+set INSTALL_ENV_DIR=%cd%\fishenv\env
+set PIP_CMD=%cd%\fishenv\env\python -m pip
+set PYTHON_CMD=%cd%\fishenv\env\python
+set API_FLAG_PATH=%~dp0API_FLAGS.txt
+set MINICONDA_DOWNLOAD_URL=https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.3.1-0-Windows-x86_64.exe
+set MINICONDA_CHECKSUM=307194e1f12bbeb52b083634e89cc67db4f7980bd542254b43d3309eaf7cb358
+set conda_exists=F
+:: 确定是否要安装conda
+call "%CONDA_ROOT_PREFIX%\_conda.exe" --version >nul 2>&1
+if "%ERRORLEVEL%" EQU "0" set conda_exists=T
+:: 下载Miniconda
+if "%conda_exists%" == "F" (
+ echo.
+ echo 正在下载Miniconda...
+ mkdir "%INSTALL_DIR%" 2>nul
+ :: 使用curl下载Miniconda安装程序
+ call curl -Lk "%MINICONDA_DOWNLOAD_URL%" > "%INSTALL_DIR%\miniconda_installer.exe"
+ :: 检查下载是否成功
+ if errorlevel 1 (
+ echo.
+ echo 下载Miniconda失败
+ goto end
+ )
+ :: 哈希校验
+ for /f %%a in ('
+ certutil -hashfile "%INSTALL_DIR%\miniconda_installer.exe" sha256
+ ^| find /i /v " "
+ ^| find /i "%MINICONDA_CHECKSUM%"
+ ') do (
+ :: 如果哈希值匹配预设的校验和,将其存储在变量中
+ set "hash=%%a"
+ )
+ if not defined hash (
+ echo.
+ echo Miniconda安装程序的哈希值不匹配
+ del "%INSTALL_DIR%\miniconda_installer.exe"
+ goto end
+ ) else (
+ echo.
+ echo Miniconda安装程序的哈希值成功匹配
+ )
+ echo 下载完成,接下来安装Miniconda至"%CONDA_ROOT_PREFIX%"
+ start /wait "" "%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /NoShortcuts=1 /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%CONDA_ROOT_PREFIX%
+ :: 测试是否成功安装
+ call "%CONDA_ROOT_PREFIX%\_conda.exe" --version
+ if errorlevel 1 (
+ echo.
+ echo 未安装Miniconda
+ goto end
+ ) else (
+ echo.
+ echo Miniconda安装成功
+ )
+ :: 删除安装程序
+ del "%INSTALL_DIR%\miniconda_installer.exe"
+)
+
+:: 创建conda环境
+if not exist "%INSTALL_ENV_DIR%" (
+ echo.
+ echo 正在创建conda环境...
+ call "%CONDA_ROOT_PREFIX%\_conda.exe" create --no-shortcuts -y -k --prefix "%INSTALL_ENV_DIR%" -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ python=3.10
+ :: 检查环境创建是否成功
+ if errorlevel 1 (
+ echo.
+ echo 创建conda环境失败
+ goto end
+ )
+)
+:: 检查是否真的创建了环境
+if not exist "%INSTALL_ENV_DIR%\python.exe" (
+ echo.
+ echo Conda环境不存在
+ goto end
+)
+:: 环境隔离
+set PYTHONNOUSERSITE=1
+set PYTHONPATH=
+set PYTHONHOME=
+set "CUDA_PATH=%INSTALL_ENV_DIR%"
+set "CUDA_HOME=%CUDA_PATH%"
+:: 激活环境
+call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%"
+:: 检查环境是否成功激活
+if errorlevel 1 (
+ echo.
+ echo 环境激活失败
+ goto end
+) else (
+ echo.
+ echo 环境激活成功
+)
+:: 安装依赖
+%PIP_CMD% show torch >nul 2>&1
+if errorlevel 1 (
+ echo.
+ echo 未安装pytorch,正在安装...
+ %PIP_CMD% install torch --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
+)
+%PIP_CMD% show torchvision >nul 2>&1
+if errorlevel 1 (
+ echo.
+ echo 未安装torchvision,正在安装...
+ %PIP_CMD% install torchvision --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
+)
+%PIP_CMD% show torchaudio >nul 2>&1
+if errorlevel 1 (
+ echo.
+ echo 未安装torchaudio,正在安装...
+ %PIP_CMD% install torchaudio --index-url https://mirror.sjtu.edu.cn/pytorch-wheels/cu121 --no-warn-script-location
+)
+%PIP_CMD% show openai-whisper >nul 2>&1
+if errorlevel 1 (
+ echo.
+ echo 未安装openai-whisper,正在安装...
+ %PIP_CMD% install -i https://pypi.tuna.tsinghua.edu.cn/simple openai-whisper --no-warn-script-location
+)
+%PIP_CMD% show fish-speech >nul 2>&1
+if errorlevel 1 (
+ echo.
+ echo 未安装fish-speech,正在安装...
+ %PIP_CMD% install -e .
+)
+
+:: 设置Hugging Face镜像源
set HF_ENDPOINT="https://hf-mirror.com"
-if exist ".\fishenv\" (
- .\fishenv\python fish_speech\webui\manage.py
+:: 设置API_FLAG
+:: 初始化API_FLAG
+set "API_FLAGS="
+set "flags="
+:: 检查API_FLAG文件是否存在
+if exist "%API_FLAG_PATH%" (
+ for /f "usebackq tokens=*" %%a in ("%API_FLAG_PATH%") do (
+ set "line=%%a"
+ :: 去除行尾的反斜杠和空白字符,并且跳过以#开头的行
+ if not "!line:~0,1!"=="#" (
+ set "line=!line: =<SPACE>!"
+ set "line=!line:\=!"
+ set "line=!line:<SPACE>= !"
+ if not "!line!"=="" (
+ set "API_FLAGS=!API_FLAGS!!line! "
+ )
+ )
+ )
+)
+:: 去除API_FLAGS变量最后的空格
+if not "!API_FLAGS!"=="" set "API_FLAGS=!API_FLAGS:~0,-1!"
+:: 看看开不开api推理
+echo !API_FLAGS! | findstr /C:"--api" >nul 2>&1
+if !errorlevel! equ 0 (
+ echo.
+ echo 启动HTTP API推理
+ set "first_arg=true"
+ for %%a in (%*) do (
+ if "!first_arg!"=="true" (
+ set "first_arg=false"
+ ) else (
+ if not "%%a"=="--api" (
+ set "flags=!flags!%%a"
+ )
+ )
+ )
+ %PYTHON_CMD% -m tools.api !flags!
) else (
- python fish_speech\webui\manage.py
+ if defined flags (
+ :: 启动WebUI推理
+ echo.
+ echo 启动WebUI推理
+ %PYTHON_CMD% -m tools.webui !flags!
+ )
)
+echo.
+echo 接下来启动页面
+%PYTHON_CMD% fish_speech\webui\manage.py
+:end
+pause
diff --git a/start_old.bat b/start_old.bat
new file mode 100644
index 0000000..9250553
--- /dev/null
+++ b/start_old.bat
@@ -0,0 +1,12 @@
+@echo off
+chcp 65001
+echo loading page...
+set PYTHONPATH=%~dp0
+set no_proxy="localhost, 127.0.0.1, 0.0.0.0"
+set HF_ENDPOINT="https://hf-mirror.com"
+
+if exist ".\fishenv\" (
+ .\fishenv\python fish_speech\webui\manage.py
+) else (
+ python fish_speech\webui\manage.py
+)
diff --git "a/start\344\271\213\345\211\215\345\256\211\350\243\205\347\216\257\345\242\203.bat" "b/start\344\271\213\345\211\215\345\256\211\350\243\205\347\216\257\345\242\203.bat"
deleted file mode 100644
index ac20476..0000000
--- "a/start\344\271\213\345\211\215\345\256\211\350\243\205\347\216\257\345\242\203.bat"
+++ /dev/null
@@ -1,33 +0,0 @@
-@echo off
-chcp 65001
-
-set no_proxy="127.0.0.1, 0.0.0.0, localhost"
-setlocal
-set PIP_CONFIG_FILE=%APPDATA%\pip\pip.ini
-
-:: 确保pip配置目录存在
-if not exist "%APPDATA%\pip\" mkdir "%APPDATA%\pip"
-
-:: 创建或修改pip.ini文件
-(
-echo [global]
-echo.
-echo index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
-echo.
-echo [install]
-echo.
-echo trusted-host =
-echo.
-echo pypi.tuna.tsinghua.edu.cn
-
-) > "%PIP_CONFIG_FILE%"
-
-echo pip配置文件已更新
-endlocal
-
-.\fishenv\python -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 --no-warn-script-location
-.\fishenv\python -m pip install -e . --no-warn-script-location
-.\fishenv\python -m pip install openai-whisper --no-warn-script-location
-
-echo OK!!
-pause
diff --git "a/\344\270\200\351\224\256\345\210\240\351\231\244\346\211\200\346\234\211\347\216\257\345\242\203(\346\205\216\347\202\271).bat" "b/\344\270\200\351\224\256\345\210\240\351\231\244\346\211\200\346\234\211\347\216\257\345\242\203(\346\205\216\347\202\271).bat"
deleted file mode 100644
index c68cf60..0000000
--- "a/\344\270\200\351\224\256\345\210\240\351\231\244\346\211\200\346\234\211\347\216\257\345\242\203(\346\205\216\347\202\271).bat"
+++ /dev/null
@@ -1,9 +0,0 @@
-@echo off
-chcp 65001
-
-.\fishenv\python -m pip freeze > installed.txt
-.\fishenv\python -m pip uninstall -r installed.txt -y
-del installed.txt -y
-
-echo OK!!
-pause