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

相关推荐
魔乐社区6 分钟前
DeepSeek在昇腾上的模型部署 - 常见问题及解决方案
人工智能·深度学习·deepseek
夜幕龙18 分钟前
深度生成模型(二)——基本概念与数学建模
人工智能·深度学习·transformer
游王子23 分钟前
OpenCV(11):人脸检测、物体识别
人工智能·opencv·计算机视觉
山海青风24 分钟前
从零开始玩转TensorFlow:小明的机器学习故事 3
人工智能·机器学习·tensorflow
@心都25 分钟前
机器学习数学基础:35.效度
人工智能·机器学习
幻想趾于现实27 分钟前
傅里叶分析
人工智能
春末的南方城市35 分钟前
VidSketch:具有扩散控制的手绘草图驱动视频生成
人工智能·深度学习·计算机视觉·aigc
Toky丶42 分钟前
【文献阅读】A Survey on Model Compression for Large Language Models
人工智能·语言模型·自然语言处理
Williams101 小时前
解锁高效开发新姿势:Trae AI编辑器深度体验
人工智能·编辑器
Francek Chen1 小时前
【大模型科普】AIGC技术发展与应用实践(一文读懂AIGC)
人工智能·深度学习·语言模型·大模型·aigc