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

相关推荐
一招定胜负1 分钟前
卷积神经网络提取人脸五个特征点
人工智能·cnn·kotlin
一招定胜负2 分钟前
回顾:cbow连续词袋与词嵌入
人工智能·自然语言处理·nlp
七夜zippoe3 分钟前
大模型低成本高性能演进 从GPT到DeepSeek的技术实战手记
人工智能·gpt·算法·架构·deepseek
Allen_LVyingbo5 分钟前
面向70B多模态医疗大模型预训练的工程落地(医疗大模型预训练扩展包)
人工智能·python·分类·知识图谱·健康医疗·迁移学习
一方_self6 分钟前
cloudflare AI gateway实战代理任意第三方大模型服务提供商
人工智能·gateway
Deng8723473486 分钟前
电脑使用 Gemini出了点问题解决办法
人工智能·python
汗流浃背了吧,老弟!8 分钟前
LangChain RAG PDF 问答 Demo
人工智能·深度学习
GJGCY10 分钟前
技术拆解:从Manus的通用推理到金智维K-APA的受控执行,企业级AI架构如何选择?
人工智能·架构
上海合宙LuatOS16 分钟前
LuatOS socket基础知识和应用开发
开发语言·人工智能·单片机·嵌入式硬件·物联网·开源·php
盖雅工场22 分钟前
业务波动适配型排班,破解零售服务业人力失衡难题
大数据·人工智能