本地部署 whisper-medusa

本地部署 whisper-medusa

  • [0. 引言](#0. 引言)
  • [1. 本地部署](#1. 本地部署)
    • [1-1. 创建虚拟环境](#1-1. 创建虚拟环境)
    • [1-2. 克隆代码](#1-2. 克隆代码)
    • [1-3. 安装依赖模块](#1-3. 安装依赖模块)
    • [1-4. 创建 Web UI](#1-4. 创建 Web UI)
    • [1-5. 启动 Web UI](#1-5. 启动 Web UI)
    • [1-5. 访问 Web UI](#1-5. 访问 Web UI)

0. 引言

Whisper 是一种用于语音转录和翻译的高级编码器-解码器模型,通过编码和解码阶段处理音频。鉴于其尺寸大和推理速度慢,人们提出了各种优化策略(例如 Faster-Whisper 和 Speculative Decoding)来提高性能。我们的 Medusa 模型建立在 Whisper 的基础上,通过每次迭代预测多个标记,这显着提高了速度,同时 WER 略有下降。我们在 LibriSpeech 数据集上训练和评估我们的模型,与普通 Whisper 模型相比,展示了强大的性能速度改进和同等准确度。

1. 本地部署

1-1. 创建虚拟环境

复制代码
conda create -n whisper-medusa python=3.11 -y
conda activate whisper-medusa

1-2. 克隆代码

复制代码
git clone https://github.com/aiola-lab/whisper-medusa.git
cd whisper-medusa

1-3. 安装依赖模块

复制代码
pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118
pip install -e .
conda install matplotlib
pip install gradio

1-4. 创建 Web UI

复制代码
# webui.py
import torch
import torchaudio
import gradio as gr
from whisper_medusa import WhisperMedusaModel
from transformers import WhisperProcessor

# Load model and processor
model_name = "aiola/whisper-medusa-v1"
model = WhisperMedusaModel.from_pretrained(model_name)
processor = WhisperProcessor.from_pretrained(model_name)

# Set device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)

# Constants
SAMPLING_RATE = 16000

def transcribe_audio(audio_file, language):
    # Load and preprocess audio
    input_speech, sr = torchaudio.load(audio_file)
    if input_speech.shape[0] > 1:  # If stereo, average the channels
        input_speech = input_speech.mean(dim=0, keepdim=True)
    if sr != SAMPLING_RATE:
        input_speech = torchaudio.transforms.Resample(sr, SAMPLING_RATE)(input_speech)
    
    # Process input
    input_features = processor(input_speech.squeeze(), return_tensors="pt", sampling_rate=SAMPLING_RATE).input_features
    input_features = input_features.to(device)
    
    # Generate transcription
    model_output = model.generate(
        input_features,
        language=language,
    )
    predict_ids = model_output[0]
    transcription = processor.decode(predict_ids, skip_special_tokens=True)
    
    return 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="text",
    title="Audio Transcription with Whisper Medusa",
    description="Upload an audio file and select the language to transcribe the audio to text."
)

# Launch the interface
iface.launch()

1-5. 启动 Web UI

复制代码
python webui.py

1-5. 访问 Web UI

使用浏览器访问 http://localhost:7860

相关推荐
xwz小王子3 小时前
拒绝视频生成,深度跃迁提出具身基座模型全新路线
人工智能·深度学习·机器学习
奈斯先生Vector3 小时前
AIGC 视频生成实战:用 Kling Video 拆解文生视频、图生视频与完整工作流
开发语言·人工智能·windows·python·aigc·音视频
m0_739312873 小时前
【自动驾驶/机器人控制】之坐标系&运动学仿真代码工程分析(一)
人工智能·机器人·自动驾驶
桃西西呀3 小时前
用 AI 写得更快,上线却容易炸?拆解 AI 编码生产力悖论的 5 个机制,附 9 个坑的自检清单
人工智能·llm·ai编程
derekwang853 小时前
驾驭 AI · AI Harness Engineering · 契约层设计
人工智能·ai编程
月华路3 小时前
《模型不玄学》第14章 标签、损失与样本权重
人工智能·算法·机器学习
DPS普轩·真空灌胶机专家4 小时前
普轩科技亮相第四届西安军工展 | 真空灌胶专家,展位 2-003
大数据·人工智能·科技·机器人·pcb工艺
台风护盾4 小时前
视频怎么自动翻译成中文字幕?AI 视频翻译的三道坎和一条捷径
人工智能·机器翻译·音频处理·ai工具·视频翻译
@嵌入式扫地僧4 小时前
嵌入式环境下麦克风阵列远场语音降噪的快速实现
人工智能·语音识别·嵌入式语音降噪·麦克风阵列·ai 降噪轻量化
行者全栈架构师4 小时前
WorkBuddy 实战:把一份 200 页年报变成可上台的投资分析 PPT
人工智能·算法·全栈