Views
No views yet
pipeline. The new features includes
(i) speaker diarization with diarizers
and (ii) adding punctuation with punctuators.
The pipeline has been developed through the collaboration between Asahi Ushio and Kotoba Technologies1pip install --upgrade pip
2pip install --upgrade transformers accelerate torchaudio
3pip install "punctuators==0.0.5"
4pip install "pyannote.audio"
5pip install git+https://github.com/huggingface/diarizers.githuggingface-cli loginpipeline.wget https://huggingface.co/kotoba-tech/kotoba-whisper-v2.2/resolve/main/sample_audio/sample_diarization_japanese.mp31import torch
2from transformers import pipeline
3
4# config
5model_id = "kotoba-tech/kotoba-whisper-v2.2"
6torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
7device = "cuda:0" if torch.cuda.is_available() else "cpu"
8model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
9
10
11# load model
12pipe = pipeline(
13 model=model_id,
14 torch_dtype=torch_dtype,
15 device=device,
16 model_kwargs=model_kwargs,
17 batch_size=8,
18 trust_remote_code=True,
19)
20
21# run inference
22result = pipe("sample_diarization_japanese.mp3", chunk_length_s=15)
23print(result)
24>>> {
25 'chunks/SPEAKER_00': [{'speaker_id': 'SPEAKER_00', 'text': '水をマレーシアから買わなくてはならないのです', 'timestamp': [22.1, 24.97]}],
26 'chunks/SPEAKER_01': [{'speaker_id': 'SPEAKER_01', 'text': 'これも先ほどがずっと言っている自分の感覚的には大丈夫ですけれども', 'timestamp': [0.03, 13.85]},
27 {'speaker_id': 'SPEAKER_01', 'text': '今は屋外の気温', 'timestamp': [5.03, 18.85]},
28 {'speaker_id': 'SPEAKER_01', 'text': '昼も夜も上がってますので', 'timestamp': [7.63, 21.45]},
29 {'speaker_id': 'SPEAKER_01', 'text': '空気の入れ替えだけではかえって人が上がってきます', 'timestamp': [9.91, 23.73]}],
30 'chunks/SPEAKER_02': [{'speaker_id': 'SPEAKER_02', 'text': '愚直にやっぱりその街の良さをアピールしていくという', 'timestamp': [13.48, 22.1]},
31 {'speaker_id': 'SPEAKER_02', 'text': 'そういう姿勢が基本にあった上での', 'timestamp': [17.26, 25.88]},
32 {'speaker_id': 'SPEAKER_02', 'text': 'こういうPR作戦だと思うんですよね', 'timestamp': [19.86, 28.48]}],
33 'chunks': [{'speaker_id': 'SPEAKER_00', 'text': '水をマレーシアから買わなくてはならないのです', 'timestamp': [22.1, 24.97]},
34 {'speaker_id': 'SPEAKER_01', 'text': 'これも先ほどがずっと言っている自分の感覚的には大丈夫ですけれども', 'timestamp': [0.03, 13.85]},
35 {'speaker_id': 'SPEAKER_01', 'text': '今は屋外の気温', 'timestamp': [5.03, 18.85]},
36 {'speaker_id': 'SPEAKER_01', 'text': '昼も夜も上がってますので', 'timestamp': [7.63, 21.45]},
37 {'speaker_id': 'SPEAKER_01', 'text': '空気の入れ替えだけではかえって人が上がってきます', 'timestamp': [9.91, 23.73]},
38 {'speaker_id': 'SPEAKER_02', 'text': '愚直にやっぱりその街の良さをアピールしていくという', 'timestamp': [13.48, 22.1]},
39 {'speaker_id': 'SPEAKER_02', 'text': 'そういう姿勢が基本にあった上での', 'timestamp': [17.26, 25.88]},
40 {'speaker_id': 'SPEAKER_02', 'text': 'こういうPR作戦だと思うんですよね', 'timestamp': [19.86, 28.48]}],
41 'speaker_ids': ['SPEAKER_00', 'SPEAKER_01', 'SPEAKER_02'],
42 'text/SPEAKER_00': '水をマレーシアから買わなくてはならないのです',
43 'text/SPEAKER_01': 'これも先ほどがずっと言っている自分の感覚的には大丈夫ですけれども今は屋外の気温昼も夜も上がってますので空気の入れ替えだけではかえって人が上がってきます',
44 'text/SPEAKER_02': '愚直にやっぱりその街の良さをアピールしていくというそういう姿勢が基本にあった上でのこういうPR作戦だと思うんですよね'
45}1- result = pipe("sample_diarization_japanese.mp3")
2+ result = pipe("sample_diarization_japanese.mp3", add_punctuation=True)text/* feature. Eg.)'text/SPEAKER_00': '水をマレーシアから買わなくてはならないのです。'
'text/SPEAKER_01': 'これも先ほどがずっと言っている。自分の感覚的には大丈夫です。けれども。今は屋外の気温、昼も夜も上がってますので、空気の入れ替えだけではかえって人が上がってきます。'
'text/SPEAKER_02': '愚直にその街の良さをアピールしていくという。そういう姿勢が基本にあった上での、こういうPR作戦だと思うんですよね。'1- result = pipe("sample_diarization_japanese.mp3")
2+ result = pipe("sample_diarization_japanese.mp3", num_speakers=3)1- result = pipe("sample_diarization_japanese.mp3")
2+ result = pipe("sample_diarization_japanese.mp3", min_speakers=2, max_speakers=5)1- result = pipe("sample_diarization_japanese.mp3")
2+ result = pipe("sample_diarization_japanese.mp3", add_silence_end=0.5, add_silence_start=0.5) # adding 0.5 sec silence to before/after the audiopip install flash-attn --no-build-isolationattn_implementation="flash_attention_2" to from_pretrained:1- model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
2+ model_kwargs = {"attn_implementation": "flash_attention_2"} if torch.cuda.is_available() else {}