本地部署 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:

相关推荐
阿里云大数据AI技术1 小时前
Agentic Memory Extension 支持对接主流Agent - 适用于 Claude Code、CodeX等
人工智能·agent
我唔知啊1 小时前
不是让 AI 写代码,我是在指挥 AI 干活:一套打磨出来的 AI 编程工作流
人工智能
ZzT1 小时前
在 GitHub 上 @一下 claude,它自己把 issue 改成 PR
人工智能·开源
不加辣椒2 小时前
第15章 上下文窗口管理与长文本策略
人工智能
牛奶3 小时前
AI 能赚钱了——但赚的不是你
人工智能·ai编程·nvidia
凌杰3 小时前
AI 学习笔记:研究方法的演变
人工智能
半盏药香3 小时前
由于jinja2的starlette版本过高引发的问题:500 Server Error TypeError: unhashable type: 'dict'
人工智能
阿里云大数据AI技术3 小时前
MiniMax M3、Kimi K2.7 Code来啦!PAI已支持一键部署,开源前沿触手可及
人工智能·agent
百度Geek说3 小时前
AI Coding 的底层框架:一切优化都是在对抗熵增
人工智能
Java研究者4 小时前
AI智能体研发 | 什么是OpenAI API协议
人工智能·大模型·openai·api·agent·智能体