license: mit
潮汕话Whisper中型模型
本模型是基于Whisper中型模型微调而成的潮汕话(潮州话)识别模型,潮汕话是中国南方闽南语系的一种方言。
关于本模型训练过程的详细说明,请观看此视频:https://www.youtube.com/watch?v=JH_78KmP4Zk
训练数据
模型使用约35小时的潮汕话影视剧和喜剧节目音频数据进行微调训练。
评估指标
在我们的私有测试集上,获得以下词错误率(WER)指标:
已知限制:该模型仅在短音频片段上训练,可能难以处理超过10秒的音频。
示例代码
以下脚本将下载模型并使用Gradio启动演示界面运行模型:
import torch
import torchaudio
from transformers import WhisperProcessor, WhisperForConditionalGeneration
import gradio as gr
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
WHISPER_SAMPLE_RATE = 16000
processor = WhisperProcessor.from_pretrained("openai/whisper-medium")
model = WhisperForConditionalGeneration.from_pretrained(
"efficient-nlp/teochew-whisper-medium"
).to(DEVICE)
def preprocess_audio(audio_path: str) -> torch.Tensor:
audio, sample_rate = torchaudio.load(audio_path)
# 必要时重采样
if sample_rate != WHISPER_SAMPLE_RATE:
resampler = torchaudio.transforms.Resample(
orig_freq=sample_rate, new_freq=WHISPER_SAMPLE_RATE
)
audio = resampler(audio)
# 转换为单声道
if audio.shape[0] > 1:
audio = torch.mean(audio, dim=0)
return audio.squeeze()
def transcribe(audio_path: str) -> str:
audio_input = preprocess_audio(audio_path)
input_features = processor(
audio_input,
sampling_rate=WHISPER_SAMPLE_RATE,
return_tensors="pt",
language="Chinese",
).input_features.to(DEVICE)
predicted_ids = model.generate(input_features)
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
return transcription
iface = gr.Interface(
fn=transcribe,
inputs=gr.Audio(type="filepath"),
outputs="text",
title="潮汕话语音识别",
)
iface.launch()