语言: 日语
库名称: transformers
许可证: apache-2.0
流水线标签: 自动语音识别
标签:
- 音频
- 自动语音识别
- hf-asr-leaderboard
小部件:
- 示例标题: 样本1
来源: https://huggingface.co/kotoba-tech/kotoba-whisper-v2.2/resolve/main/sample_audio/sample_diarization_japanese.mp3
Kotoba-Whisper-v2.2
Kotoba-Whisper-v2.2 是基于 kotoba-tech/kotoba-whisper-v2.0 的日语自动语音识别(ASR)模型,集成了额外的后处理栈作为 pipeline
。新功能包括:
(i) 使用 diarizers 进行说话人分离
(ii) 使用 punctuators 添加标点符号
该流水线由 Asahi Ushio 与 Kotoba Technologies 合作开发
Transformers 使用指南
Kotoba-Whisper-v2.2 从 4.39 版本开始支持 Hugging Face 🤗 Transformers 库。运行模型前,请先安装最新版 Transformers:
pip install --upgrade pip
pip install --upgrade transformers accelerate torchaudio
pip install "punctuators==0.0.5"
pip install "pyannote.audio"
pip install git+https://github.com/huggingface/diarizers.git
从 Hub 加载预训练的说话人分离模型前,需先同意以下两个模型的使用条款:
- pyannote/segmentation-3.0
- pyannote/speaker-diarization-3.1
随后使用 Hugging Face 认证令牌登录:
huggingface-cli login
带说话人分离的转录
可通过 pipeline
使用该模型。
wget https://huggingface.co/kotoba-tech/kotoba-whisper-v2.2/resolve/main/sample_audio/sample_diarization_japanese.mp3
import torch
from transformers import pipeline
model_id = "kotoba-tech/kotoba-whisper-v2.2"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
pipe = pipeline(
model=model_id,
torch_dtype=torch_dtype,
device=device,
model_kwargs=model_kwargs,
batch_size=8,
trust_remote_code=True,
)
result = pipe("sample_diarization_japanese.mp3", chunk_length_s=15)
print(result)
>>> {
'chunks/SPEAKER_00': [{'speaker_id': 'SPEAKER_00', 'text': '水をマレーシアから買わなくてはならないのです', 'timestamp': [22.1, 24.97]}],
'chunks/SPEAKER_01': [{'speaker_id': 'SPEAKER_01', 'text': 'これも先ほどがずっと言っている自分の感覚的には大丈夫ですけれども', 'timestamp': [0.03, 13.85]},
{'speaker_id': 'SPEAKER_01', 'text': '今は屋外の気温', 'timestamp': [5.03, 18.85]},
{'speaker_id': 'SPEAKER_01', 'text': '昼も夜も上がってますので', 'timestamp': [7.63, 21.45]},
{'speaker_id': 'SPEAKER_01', 'text': '空気の入れ替えだけではかえって人が上がってきます', 'timestamp': [9.91, 23.73]}],
'chunks/SPEAKER_02': [{'speaker_id': 'SPEAKER_02', 'text': '愚直にやっぱりその街の良さをアピールしていくという', 'timestamp': [13.48, 22.1]},
{'speaker_id': 'SPEAKER_02', 'text': 'そういう姿勢が基本にあった上での', 'timestamp': [17.26, 25.88]},
{'speaker_id': 'SPEAKER_02', 'text': 'こういうPR作戦だと思うんですよね', 'timestamp': [19.86, 28.48]}],
'chunks': [{'speaker_id': 'SPEAKER_00', 'text': '水をマレーシアから買わなくてはならないのです', 'timestamp': [22.1, 24.97]},
{'speaker_id': 'SPEAKER_01', 'text': 'これも先ほどがずっと言っている自分の感覚的には大丈夫ですけれども', 'timestamp': [0.03, 13.85]},
{'speaker_id': 'SPEAKER_01', 'text': '今は屋外の気温', 'timestamp': [5.03, 18.85]},
{'speaker_id': 'SPEAKER_01', 'text': '昼も夜も上がってますので', 'timestamp': [7.63, 21.45]},
{'speaker_id': 'SPEAKER_01', 'text': '空気の入れ替えだけではかえって人が上がってきます', 'timestamp': [9.91, 23.73]},
{'speaker_id': 'SPEAKER_02', 'text': '愚直にやっぱりその街の良さをアピールしていくという', 'timestamp': [13.48, 22.1]},
{'speaker_id': 'SPEAKER_02', 'text': 'そういう姿勢が基本にあった上での', 'timestamp': [17.26, 25.88]},
{'speaker_id': 'SPEAKER_02', 'text': 'こういうPR作戦だと思うんですよね', 'timestamp': [19.86, 28.48]}],
'speaker_ids': ['SPEAKER_00', 'SPEAKER_01', 'SPEAKER_02'],
'text/SPEAKER_00': '水をマレーシアから買わなくてはならないのです',
'text/SPEAKER_01': 'これも先ほどがずっと言っている自分の感覚的には大丈夫ですけれども今は屋外の気温昼も夜も上がってますので空気の入れ替えだけではかえって人が上がってきます',
'text/SPEAKER_02': '愚直にやっぱりその街の良さをアピールしていくというそういう姿勢が基本にあった上でのこういうPR作戦だと思うんですよね'
}
- result = pipe("sample_diarization_japanese.mp3")
+ result = pipe("sample_diarization_japanese.mp3", add_punctuation=True)
标点符号将应用于 text/*
特征。例如:
'text/SPEAKER_00': '水をマレーシアから買わなくてはならないのです。'
'text/SPEAKER_01': 'これも先ほどがずっと言っている。自分の感覚的には大丈夫です。けれども。今は屋外の気温、昼も夜も上がってますので、空気の入れ替えだけではかえって人が上がってきます。'
'text/SPEAKER_02': '愚直にその街の良さをアピールしていくという。そういう姿勢が基本にあった上での、こういうPR作戦だと思うんですよね。'
- result = pipe("sample_diarization_japanese.mp3")
+ result = pipe("sample_diarization_japanese.mp3", num_speakers=3)
或
- result = pipe("sample_diarization_japanese.mp3")
+ result = pipe("sample_diarization_japanese.mp3", min_speakers=2, max_speakers=5)
- result = pipe("sample_diarization_japanese.mp3")
+ result = pipe("sample_diarization_japanese.mp3", add_silence_end=0.5, add_silence_start=0.5) # 在音频前后添加0.5秒静音
Flash Attention 2
如果GPU支持,建议使用 Flash-Attention 2。首先需安装 Flash Attention:
pip install flash-attn --no-build-isolation
然后向 from_pretrained
传递 attn_implementation="flash_attention_2"
:
- model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
+ model_kwargs = {"attn_implementation": "flash_attention_2"} if torch.cuda.is_available() else {}
致谢