Docker搭建SenseVoice

注意要使用githubcodespace来构建,防止网络原因构建失败

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt install git python3.10 ffmpeg pip -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN git clone --depth 1 https://github.com/FunAudioLLM/SenseVoice /SenseVoice

WORKDIR /SenseVoice

# Install the dependencies
RUN pip install --no-cache-dir setuptools onnx onnxconverter_common
RUN pip install --no-cache-dir -r requirements.txt

# 下载模型文件
RUN python3 -c "from funasr import AutoModel; model = AutoModel(model='iic/SenseVoiceSmall', vad_model='iic/speech_fsmn_vad_zh-cn-16k-common-pytorch', vad_kwargs={'max_single_segment_time': 30000}, trust_remote_code=True)"

# 模型文件移动到启动目录,防止离线环境卡在联网校验环节导致启动失败
RUN mv /root/.cache/modelscope/hub/iic /SenseVoice/&&rm -rf /root/.cache/modelscope

RUN wget -O /usr/local/lib/python3.10/dist-packages/gradio/templates/frontend/assets/iframeResizer.contentWindow.min.js \
https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js

RUN find /usr/local/lib/python3.10/dist-packages/gradio/templates -type f -exec sed -i \
    -e 's/https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/iframe-resizer\/4.3.1\/iframeResizer.contentWindow.min.js/assets\/iframeResizer.contentWindow.min.js/g' {} +

# 修改监听地址并汉化
RUN sed -i \
    -e 's/label="Language"/label="语言"/g' \
    -e 's/"Configuration"/"设置"/g' \
    -e 's/value="auto"/value="zh"/g' \
    -e 's/Button("Start"/Button("开始识别"/g' \
    -e 's/label="Results"/label="识别结果"/g' \
    -e 's/demo\.launch()/demo.launch(server_name="0.0.0.0")/g' \
    -e 's/label="Upload audio or use the microphone"/label="上传音频文件或者使用话筒录制音频"/g' \
    -e '/^[[:space:]]*gr\.\(Examples\|HTML\)/ s/^/#/' \
    webui.py

# Expose port
EXPOSE 7860

CMD ["python3", "webui.py"]

拉取

1
docker pull registry.cn-hangzhou.aliyuncs.com/btzry/sensevoice