本地部署 faster-whisper

本地部署 faster-whisper

  • [1. 创建虚拟环境](#1. 创建虚拟环境)
  • [2. 安装依赖模块](#2. 安装依赖模块)
  • [3. 创建 Web UI](#3. 创建 Web UI)
  • [4. 启动 Web UI](#4. 启动 Web UI)
  • [5. 访问 Web UI](#5. 访问 Web UI)

1. 创建虚拟环境

复制代码
conda create -n faster-whisper python=3.11 -y
conda activate faster-whisper

2. 安装依赖模块

复制代码
pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118
pip install faster-whisper
conda install matplotlib
pip install gradio

3. 创建 Web UI

复制代码
# webui.py
import gradio as gr
from faster_whisper import WhisperModel

# Initialize the model
# model_size = "large-v3"
model_size = "Systran/faster-whisper-large-v3"
model = WhisperModel(model_size, device="cuda", compute_type="float16")

def transcribe_audio(audio_file, language):
    # Transcribe the audio
    segments, info = model.transcribe(audio_file, beam_size=5, language=language)

    # Prepare the output
    transcription = ""
    for segment in segments:
        transcription += f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}\n"

    detected_language = f"Detected language: {info.language} (probability: {info.language_probability:.2f})"

    return detected_language, transcription

# Define Gradio interface
iface = gr.Interface(
    fn=transcribe_audio,
    inputs=[
        gr.Audio(type="filepath", label="Upload Audio"),
        gr.Dropdown(["en", "zh", "ja"], label="Select Language", value="en")
    ],
    outputs=[
        gr.Textbox(label="Detected Language"),
        gr.Textbox(label="Transcription", lines=20)
    ],
    allow_flagging='never',
    title="Audio Transcription with Faster Whisper",
    description="Upload an audio file and select the language to transcribe the audio to text. Choose 'auto' for automatic language detection."
)

# Launch the interface
iface.launch()

4. 启动 Web UI

复制代码
python webui.py

5. 访问 Web UI

使用浏览器打开 http://localhost:7860,

reference:

相关推荐
sinat_323960376 小时前
老游戏怎么被重写:读 OpenRCT2
人工智能
汤姆宝库6 小时前
推理级联的实现:置信度估计与FrugalGPT式路由
人工智能
gptAI_plus7 小时前
GPT 写 SQL:避免订单金额被重复统计
人工智能
吕炘嵘7 小时前
会背答案,不会修 Bug——一次 0.6B模型Java 微调复盘
人工智能
Thomas.Sir7 小时前
第017讲:AI模型开发|可行性评分卡与一票否决:把主观判断结构化:数据不及格,其余满分也必须 No-Go
人工智能·ai
JonaHu7 小时前
GPT Image 2.6 商品图横竖版适配:安全区、留白与裁切预检
图像处理·人工智能·python·aigc
AAA修煤气灶刘哥7 小时前
一口气拍 30 秒,MAGI-2 能接下 Seedance 2.5 的活吗?
人工智能·llm
AI 编程助手GPT7 小时前
GPT 写 SQL:避免订单金额被重复统计
jvm·人工智能·sql·gpt
AAA修煤气灶刘哥7 小时前
QQ 音乐怎么在 25 毫秒内,决定一句话该交给谁?
人工智能·算法·llm
oil欧哟7 小时前
Skill 编写最佳实践:核心原理与实战拆解
人工智能