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

相关推荐
Hcoco_me3 分钟前
具身智能 && 自动驾驶相关岗位的技术栈与能力地图
人工智能·机器学习·自动驾驶
yinyan131430 分钟前
一起学springAI系列一:初体验
java·人工智能·ai
一只鹿鹿鹿1 小时前
【网络安全】信息网络安全建设方案(WORD)
人工智能·安全·spring·web安全·低代码
小拇指~1 小时前
梯度下降的基本原理
人工智能·算法·计算机视觉
AndrewHZ1 小时前
【图像处理基石】如何对遥感图像进行实例分割?
图像处理·人工智能·python·大模型·实例分割·detectron2·遥感图像分割
CodeShare2 小时前
某中心将举办机器学习峰会
人工智能·机器学习·数据科学
那就摆吧2 小时前
U-Net vs. 传统CNN:为什么医学图像分割需要跳过连接?
人工智能·神经网络·cnn·u-net·医学图像
深度学习实战训练营2 小时前
中英混合的语音识别XPhoneBERT 监督的音频到音素的编码器结合 f0 特征LID
人工智能·音视频·语音识别
WADesk---瓜子2 小时前
用 AI 自动生成口型同步视频,短视频内容也能一人完成
人工智能·音视频·语音识别·流量运营·用户运营
星环科技TDH社区版3 小时前
AI Agent 的 10 种应用场景:物联网、RAG 与灾难响应
人工智能·物联网