build Paraformer-large ASR docker 镜像

创建日期: 2025-07-25 16:05 | 作者: 风波 | 浏览次数: 24 | 分类: AI

官方地址:https://www.modelscope.cn/models/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch

1. Dockerfile

FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*
RUN apt-get update --allow-releaseinfo-change

RUN apt install software-properties-common -y

RUN add-apt-repository ppa:deadsnakes/ppa -y

RUN apt install python3.10 python3.10-venv python3.10-dev -y

RUN python3.10 -m venv /opt/venv

ENV VIRTUAL_ENV=/opt/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

RUN apt install -y libgl1

RUN apt install -y libgl1 libglib2.0-0 libsm6 libxext6 libxrender1

RUN pip install --upgrade pip setuptools wheel

RUN pip install modelscope -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

RUN pip install onnxruntime -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

RUN pip install funasr -i https://pypi.tuna.tsinghua.edu.cn/simple/

RUN pip install addict datasets==2.16.0 pyarrow==20.0.0 -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

RUN pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

RUN pip install simplejson sortedcontainers -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

RUN apt install libgomp1 -y

RUN apt install ffmpeg -y

RUN pip install numpy==1.26.4 -i https://mirrors.aliyun.com/pypi/simple/  --trusted-host mirrors.aliyun.com

COPY ./speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch /opt/modelscope/hub/models/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch

其中的本地目录 speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch 是通过下面命令进行下载的

from modelscope import snapshot_download
model_dir = snapshot_download('iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch')

print(model_dir)

2. docker-compose.yml

services:
  paraformer-large:
    build:
      context: docker
      dockerfile: ./Dockerfile
    image: paraformer-large:v1

3. 使用方式

from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
import sys

inference_pipeline = pipeline(
        task=Tasks.auto_speech_recognition,
        model='/opt/modelscope/hub/models/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch',
        model_revision="master",
        device="cuda:0",)

for filename in sys.argv[1:]:
    #rec_result = inference_pipeline('https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav')
    rec_result = inference_pipeline(filename)
    print(rec_result)

filename 可以是本地文件,也可以是 url

注意⚠️:输入音频为pcm格式,调用api时需要传入音频采样率参数audio_fs (https://www.modelscope.cn/models/iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch )

可以使用下面的命令进行音频格式转换 ffmpeg -i 111.mp3 -acodec pcm_s16le -ac 1 -ar 16000 out.wav

24 浏览
14 爬虫
0 评论