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

相关推荐
元闰子7 分钟前
AI Agent需要什么样的数据库?
数据库·人工智能·后端
蚂蚁数据AntData8 分钟前
⼤模型驱动的DeepInsight Copilot在蚂蚁的技术实践
大数据·人工智能·数据分析·copilot·数据库架构
LeonDL16810 分钟前
HALCON 深度学习训练 3D 图像的几种方式优缺点
人工智能·python·深度学习·3d·halcon·halcon训练3d图像·深度学习训练3d图像
jmsail11 分钟前
Dynamics 365 Business Central AI Sales Order Agent Copilot
人工智能·microsoft·copilot·dynamics 365·d365 bc erp
要养家的程序猿27 分钟前
RagFlow优化&代码解析(一)
人工智能·ai
凯禾瑞华现代家政43 分钟前
适老化场景重构:现代家政老年照护虚拟仿真实训室建设方案
人工智能·系统架构·虚拟现实
Wnq100721 小时前
通用人工智能 (AGI): 定义、挑战与未来展望
人工智能·agi
宋一诺331 小时前
机器学习——放回抽样
人工智能·机器学习
Ao0000001 小时前
机器学习——主成分分析PCA
人工智能·机器学习