Downloads · 30 days
8
2% of all-time downloads
reachan/Cantonese-Whisper-Medium
Cantonese-Whisper-Medium is a automatic speech recognition model from reachan. Use it when you need speech turned into text. It is set up for transformers.
The model is trained on multiple public Cantonese ASR datasets with 100.5 hours of audio data. Fine-tuning based on the Whisper-Medium Chinese model
Downloads · 30 days
8
2% of all-time downloads
All-time downloads
351
Public
Parameters
764M
3.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors3.1 GB · 100%
From the Hugging Face model README
The model is trained on multiple public Cantonese ASR datasets with 100.5 hours of audio data. Fine-tuning based on the Whisper-Medium Chinese model
| Model | openai/whisper-medium | reachan/Cantonese-Whisper-Medium |
|---|---|---|
| WER | 0.94438 | 0.39383 |
| CER | 0.38508 | 0.06281 |
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(
"reachan/Cantonese-Whisper-Medium"
).to(DEVICE)
def preprocess_audio(audio_path: str) -> torch.Tensor:
audio, sample_rate = torchaudio.load(audio_path)
# Resample if necessary
if sample_rate != WHISPER_SAMPLE_RATE:
resampler = torchaudio.transforms.Resample(
orig_freq=sample_rate, new_freq=WHISPER_SAMPLE_RATE
)
audio = resampler(audio)
# Convert to mono
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="Cantonese Speech Recognition",
)
iface.launch()