🚀 波斯语语音识别模型 - whisper-persian-turbooo
本项目是一个用于自动语音识别的模型,基于openai/whisper-large-v3-turbo
微调而来,可处理波斯语语音,适用于医疗等领域。
🚀 快速开始
模型使用环境
- 数据集:
mozilla-foundation/common_voice_11_0
- 评估指标:
wer
(词错误率)
- 基础模型:
openai/whisper-large-v3-turbo
- 库名称:
transformers
- 标签:
medical
训练信息
属性 |
详情 |
训练损失 |
0.013100 |
验证损失 |
0.043175 |
训练轮数 |
1 |
许可证
本项目采用 MIT 许可证。
📦 安装指南
在 Colab 中使用该模型,需要安装必要的包:
!pip install torch torchaudio transformers pydub google-colab
💻 使用示例
基础用法
以下是在 Colab 中使用该模型进行波斯语语音转录的完整代码:
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from pydub import AudioSegment
import os
from google.colab import files
model_id = "hackergeek98/whisper-persian-turbooo"
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id).to(device)
processor = AutoProcessor.from_pretrained(model_id)
whisper_pipe = pipeline(
"automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, device=0 if torch.cuda.is_available() else -1
)
def convert_to_wav(audio_path):
audio = AudioSegment.from_file(audio_path)
wav_path = "converted_audio.wav"
audio.export(wav_path, format="wav")
return wav_path
def split_audio(audio_path, chunk_length_ms=30000):
audio = AudioSegment.from_wav(audio_path)
chunks = [audio[i:i+chunk_length_ms] for i in range(0, len(audio), chunk_length_ms)]
chunk_paths = []
for i, chunk in enumerate(chunks):
chunk_path = f"chunk_{i}.wav"
chunk.export(chunk_path, format="wav")
chunk_paths.append(chunk_path)
return chunk_paths
def transcribe_long_audio(audio_path):
wav_path = convert_to_wav(audio_path)
chunk_paths = split_audio(wav_path)
transcription = ""
for chunk in chunk_paths:
result = whisper_pipe(chunk)
transcription += result["text"] + "\n"
os.remove(chunk)
os.remove(wav_path)
text_path = "transcription.txt"
with open(text_path, "w") as f:
f.write(transcription)
return text_path
uploaded = files.upload()
audio_file = list(uploaded.keys())[0]
transcription_file = transcribe_long_audio(audio_file)
files.download(transcription_file)
代码说明
上述代码实现了在 Colab 中上传音频文件,将其转换为 WAV 格式,分割长音频为小块,使用模型进行转录,并最终下载转录结果的功能。你可以根据实际需求调整代码中的参数,如音频分割的时长等。