Spaces:
Build error
Build error
Duplicate from vumichien/whisper-speaker-diarization
Browse filesCo-authored-by: vumichien <[email protected]>
- .gitattributes +34 -0
- README.md +15 -0
- app.py +414 -0
- packages.txt +1 -0
- requirements.txt +21 -0
- sample1.wav +0 -0
- sample2.wav +0 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Whisper Speaker Diarization
|
3 |
+
emoji: 🎎
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.9.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
tags:
|
11 |
+
- whisper-event
|
12 |
+
duplicated_from: vumichien/whisper-speaker-diarization
|
13 |
+
---
|
14 |
+
|
15 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import datetime
|
3 |
+
import subprocess
|
4 |
+
import gradio as gr
|
5 |
+
from pathlib import Path
|
6 |
+
import pandas as pd
|
7 |
+
import re
|
8 |
+
import time
|
9 |
+
import os
|
10 |
+
import numpy as np
|
11 |
+
from sklearn.cluster import AgglomerativeClustering
|
12 |
+
|
13 |
+
from pytube import YouTube
|
14 |
+
import torch
|
15 |
+
import pyannote.audio
|
16 |
+
from pyannote.audio.pipelines.speaker_verification import PretrainedSpeakerEmbedding
|
17 |
+
from pyannote.audio import Audio
|
18 |
+
from pyannote.core import Segment
|
19 |
+
|
20 |
+
from gpuinfo import GPUInfo
|
21 |
+
|
22 |
+
import wave
|
23 |
+
import contextlib
|
24 |
+
from transformers import pipeline
|
25 |
+
import psutil
|
26 |
+
|
27 |
+
whisper_models = ["base", "small", "medium", "large"]
|
28 |
+
source_languages = {
|
29 |
+
"en": "English",
|
30 |
+
"zh": "Chinese",
|
31 |
+
"de": "German",
|
32 |
+
"es": "Spanish",
|
33 |
+
"ru": "Russian",
|
34 |
+
"ko": "Korean",
|
35 |
+
"fr": "French",
|
36 |
+
"ja": "Japanese",
|
37 |
+
"pt": "Portuguese",
|
38 |
+
"tr": "Turkish",
|
39 |
+
"pl": "Polish",
|
40 |
+
"ca": "Catalan",
|
41 |
+
"nl": "Dutch",
|
42 |
+
"ar": "Arabic",
|
43 |
+
"sv": "Swedish",
|
44 |
+
"it": "Italian",
|
45 |
+
"id": "Indonesian",
|
46 |
+
"hi": "Hindi",
|
47 |
+
"fi": "Finnish",
|
48 |
+
"vi": "Vietnamese",
|
49 |
+
"he": "Hebrew",
|
50 |
+
"uk": "Ukrainian",
|
51 |
+
"el": "Greek",
|
52 |
+
"ms": "Malay",
|
53 |
+
"cs": "Czech",
|
54 |
+
"ro": "Romanian",
|
55 |
+
"da": "Danish",
|
56 |
+
"hu": "Hungarian",
|
57 |
+
"ta": "Tamil",
|
58 |
+
"no": "Norwegian",
|
59 |
+
"th": "Thai",
|
60 |
+
"ur": "Urdu",
|
61 |
+
"hr": "Croatian",
|
62 |
+
"bg": "Bulgarian",
|
63 |
+
"lt": "Lithuanian",
|
64 |
+
"la": "Latin",
|
65 |
+
"mi": "Maori",
|
66 |
+
"ml": "Malayalam",
|
67 |
+
"cy": "Welsh",
|
68 |
+
"sk": "Slovak",
|
69 |
+
"te": "Telugu",
|
70 |
+
"fa": "Persian",
|
71 |
+
"lv": "Latvian",
|
72 |
+
"bn": "Bengali",
|
73 |
+
"sr": "Serbian",
|
74 |
+
"az": "Azerbaijani",
|
75 |
+
"sl": "Slovenian",
|
76 |
+
"kn": "Kannada",
|
77 |
+
"et": "Estonian",
|
78 |
+
"mk": "Macedonian",
|
79 |
+
"br": "Breton",
|
80 |
+
"eu": "Basque",
|
81 |
+
"is": "Icelandic",
|
82 |
+
"hy": "Armenian",
|
83 |
+
"ne": "Nepali",
|
84 |
+
"mn": "Mongolian",
|
85 |
+
"bs": "Bosnian",
|
86 |
+
"kk": "Kazakh",
|
87 |
+
"sq": "Albanian",
|
88 |
+
"sw": "Swahili",
|
89 |
+
"gl": "Galician",
|
90 |
+
"mr": "Marathi",
|
91 |
+
"pa": "Punjabi",
|
92 |
+
"si": "Sinhala",
|
93 |
+
"km": "Khmer",
|
94 |
+
"sn": "Shona",
|
95 |
+
"yo": "Yoruba",
|
96 |
+
"so": "Somali",
|
97 |
+
"af": "Afrikaans",
|
98 |
+
"oc": "Occitan",
|
99 |
+
"ka": "Georgian",
|
100 |
+
"be": "Belarusian",
|
101 |
+
"tg": "Tajik",
|
102 |
+
"sd": "Sindhi",
|
103 |
+
"gu": "Gujarati",
|
104 |
+
"am": "Amharic",
|
105 |
+
"yi": "Yiddish",
|
106 |
+
"lo": "Lao",
|
107 |
+
"uz": "Uzbek",
|
108 |
+
"fo": "Faroese",
|
109 |
+
"ht": "Haitian creole",
|
110 |
+
"ps": "Pashto",
|
111 |
+
"tk": "Turkmen",
|
112 |
+
"nn": "Nynorsk",
|
113 |
+
"mt": "Maltese",
|
114 |
+
"sa": "Sanskrit",
|
115 |
+
"lb": "Luxembourgish",
|
116 |
+
"my": "Myanmar",
|
117 |
+
"bo": "Tibetan",
|
118 |
+
"tl": "Tagalog",
|
119 |
+
"mg": "Malagasy",
|
120 |
+
"as": "Assamese",
|
121 |
+
"tt": "Tatar",
|
122 |
+
"haw": "Hawaiian",
|
123 |
+
"ln": "Lingala",
|
124 |
+
"ha": "Hausa",
|
125 |
+
"ba": "Bashkir",
|
126 |
+
"jw": "Javanese",
|
127 |
+
"su": "Sundanese",
|
128 |
+
}
|
129 |
+
|
130 |
+
source_language_list = [key[0] for key in source_languages.items()]
|
131 |
+
|
132 |
+
MODEL_NAME = "vumichien/whisper-medium-jp"
|
133 |
+
lang = "ja"
|
134 |
+
|
135 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
136 |
+
pipe = pipeline(
|
137 |
+
task="automatic-speech-recognition",
|
138 |
+
model=MODEL_NAME,
|
139 |
+
chunk_length_s=30,
|
140 |
+
device=device,
|
141 |
+
)
|
142 |
+
|
143 |
+
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
|
144 |
+
|
145 |
+
embedding_model = PretrainedSpeakerEmbedding(
|
146 |
+
"speechbrain/spkrec-ecapa-voxceleb",
|
147 |
+
device=torch.device("cuda" if torch.cuda.is_available() else "cpu"))
|
148 |
+
|
149 |
+
def transcribe(microphone, file_upload):
|
150 |
+
warn_output = ""
|
151 |
+
if (microphone is not None) and (file_upload is not None):
|
152 |
+
warn_output = (
|
153 |
+
"WARNING: You've uploaded an audio file and used the microphone. "
|
154 |
+
"The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
|
155 |
+
)
|
156 |
+
|
157 |
+
elif (microphone is None) and (file_upload is None):
|
158 |
+
return "ERROR: You have to either use the microphone or upload an audio file"
|
159 |
+
|
160 |
+
file = microphone if microphone is not None else file_upload
|
161 |
+
|
162 |
+
text = pipe(file)["text"]
|
163 |
+
|
164 |
+
return warn_output + text
|
165 |
+
|
166 |
+
def _return_yt_html_embed(yt_url):
|
167 |
+
video_id = yt_url.split("?v=")[-1]
|
168 |
+
HTML_str = (
|
169 |
+
f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
|
170 |
+
" </center>"
|
171 |
+
)
|
172 |
+
return HTML_str
|
173 |
+
|
174 |
+
def yt_transcribe(yt_url):
|
175 |
+
yt = YouTube(yt_url)
|
176 |
+
html_embed_str = _return_yt_html_embed(yt_url)
|
177 |
+
stream = yt.streams.filter(only_audio=True)[0]
|
178 |
+
stream.download(filename="audio.mp3")
|
179 |
+
|
180 |
+
text = pipe("audio.mp3")["text"]
|
181 |
+
|
182 |
+
return html_embed_str, text
|
183 |
+
|
184 |
+
def convert_time(secs):
|
185 |
+
return datetime.timedelta(seconds=round(secs))
|
186 |
+
|
187 |
+
def get_youtube(video_url):
|
188 |
+
yt = YouTube(video_url)
|
189 |
+
abs_video_path = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()
|
190 |
+
print("Success download video")
|
191 |
+
print(abs_video_path)
|
192 |
+
return abs_video_path
|
193 |
+
|
194 |
+
def speech_to_text(video_file_path, selected_source_lang, whisper_model, num_speakers):
|
195 |
+
"""
|
196 |
+
# Transcribe youtube link using OpenAI Whisper
|
197 |
+
1. Using Open AI's Whisper model to seperate audio into segments and generate transcripts.
|
198 |
+
2. Generating speaker embeddings for each segments.
|
199 |
+
3. Applying agglomerative clustering on the embeddings to identify the speaker for each segment.
|
200 |
+
|
201 |
+
Speech Recognition is based on models from OpenAI Whisper https://github.com/openai/whisper
|
202 |
+
Speaker diarization model and pipeline from by https://github.com/pyannote/pyannote-audio
|
203 |
+
"""
|
204 |
+
|
205 |
+
model = whisper.load_model(whisper_model)
|
206 |
+
time_start = time.time()
|
207 |
+
if(video_file_path == None):
|
208 |
+
raise ValueError("Error no video input")
|
209 |
+
print(video_file_path)
|
210 |
+
|
211 |
+
try:
|
212 |
+
# Read and convert youtube video
|
213 |
+
_,file_ending = os.path.splitext(f'{video_file_path}')
|
214 |
+
print(f'file enging is {file_ending}')
|
215 |
+
audio_file = video_file_path.replace(file_ending, ".wav")
|
216 |
+
print("starting conversion to wav")
|
217 |
+
os.system(f'ffmpeg -i "{video_file_path}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
|
218 |
+
|
219 |
+
# Get duration
|
220 |
+
with contextlib.closing(wave.open(audio_file,'r')) as f:
|
221 |
+
frames = f.getnframes()
|
222 |
+
rate = f.getframerate()
|
223 |
+
duration = frames / float(rate)
|
224 |
+
print(f"conversion to wav ready, duration of audio file: {duration}")
|
225 |
+
|
226 |
+
# Transcribe audio
|
227 |
+
options = dict(language=selected_source_lang, beam_size=5, best_of=5)
|
228 |
+
transcribe_options = dict(task="transcribe", **options)
|
229 |
+
result = model.transcribe(audio_file, **transcribe_options)
|
230 |
+
segments = result["segments"]
|
231 |
+
print("starting whisper done with whisper")
|
232 |
+
except Exception as e:
|
233 |
+
raise RuntimeError("Error converting video to audio")
|
234 |
+
|
235 |
+
try:
|
236 |
+
# Create embedding
|
237 |
+
def segment_embedding(segment):
|
238 |
+
audio = Audio()
|
239 |
+
start = segment["start"]
|
240 |
+
# Whisper overshoots the end timestamp in the last segment
|
241 |
+
end = min(duration, segment["end"])
|
242 |
+
clip = Segment(start, end)
|
243 |
+
waveform, sample_rate = audio.crop(audio_file, clip)
|
244 |
+
return embedding_model(waveform[None])
|
245 |
+
|
246 |
+
embeddings = np.zeros(shape=(len(segments), 192))
|
247 |
+
for i, segment in enumerate(segments):
|
248 |
+
embeddings[i] = segment_embedding(segment)
|
249 |
+
embeddings = np.nan_to_num(embeddings)
|
250 |
+
print(f'Embedding shape: {embeddings.shape}')
|
251 |
+
|
252 |
+
# Assign speaker label
|
253 |
+
clustering = AgglomerativeClustering(num_speakers).fit(embeddings)
|
254 |
+
labels = clustering.labels_
|
255 |
+
for i in range(len(segments)):
|
256 |
+
segments[i]["speaker"] = 'SPEAKER ' + str(labels[i] + 1)
|
257 |
+
|
258 |
+
# Make output
|
259 |
+
objects = {
|
260 |
+
'Start' : [],
|
261 |
+
'End': [],
|
262 |
+
'Speaker': [],
|
263 |
+
'Text': []
|
264 |
+
}
|
265 |
+
text = ''
|
266 |
+
for (i, segment) in enumerate(segments):
|
267 |
+
if i == 0 or segments[i - 1]["speaker"] != segment["speaker"]:
|
268 |
+
objects['Start'].append(str(convert_time(segment["start"])))
|
269 |
+
objects['Speaker'].append(segment["speaker"])
|
270 |
+
if i != 0:
|
271 |
+
objects['End'].append(str(convert_time(segments[i - 1]["end"])))
|
272 |
+
objects['Text'].append(text)
|
273 |
+
text = ''
|
274 |
+
text += segment["text"] + ' '
|
275 |
+
objects['End'].append(str(convert_time(segments[i - 1]["end"])))
|
276 |
+
objects['Text'].append(text)
|
277 |
+
|
278 |
+
time_end = time.time()
|
279 |
+
time_diff = time_end - time_start
|
280 |
+
memory = psutil.virtual_memory()
|
281 |
+
gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
|
282 |
+
gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
|
283 |
+
gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
|
284 |
+
system_info = f"""
|
285 |
+
*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
|
286 |
+
*Processing time: {time_diff:.5} seconds.*
|
287 |
+
*GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}MiB.*
|
288 |
+
"""
|
289 |
+
|
290 |
+
return pd.DataFrame(objects), system_info
|
291 |
+
|
292 |
+
except Exception as e:
|
293 |
+
raise RuntimeError("Error Running inference with local model", e)
|
294 |
+
|
295 |
+
|
296 |
+
# ---- Gradio Layout -----
|
297 |
+
# Inspiration from https://huggingface.co/spaces/RASMUS/Whisper-youtube-crosslingual-subtitles
|
298 |
+
video_in = gr.Video(label="Video file", mirror_webcam=False)
|
299 |
+
youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
|
300 |
+
df_init = pd.DataFrame(columns=['Start', 'End', 'Speaker', 'Text'])
|
301 |
+
memory = psutil.virtual_memory()
|
302 |
+
selected_source_lang = gr.Dropdown(choices=source_language_list, type="value", value="en", label="Spoken language in video", interactive=True)
|
303 |
+
selected_whisper_model = gr.Dropdown(choices=whisper_models, type="value", value="base", label="Selected Whisper model", interactive=True)
|
304 |
+
number_speakers = gr.Number(precision=0, value=2, label="Selected number of speakers", interactive=True)
|
305 |
+
system_info = gr.Markdown(f"*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB*")
|
306 |
+
transcription_df = gr.DataFrame(value=df_init,label="Transcription dataframe", row_count=(0, "dynamic"), max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
|
307 |
+
title = "Whisper speaker diarization"
|
308 |
+
demo = gr.Blocks(title=title)
|
309 |
+
demo.encrypt = False
|
310 |
+
|
311 |
+
|
312 |
+
with demo:
|
313 |
+
with gr.Tab("Whisper speaker diarization"):
|
314 |
+
gr.Markdown('''
|
315 |
+
<div>
|
316 |
+
<h1 style='text-align: center'>Whisper speaker diarization</h1>
|
317 |
+
This space uses Whisper models from <a href='https://github.com/openai/whisper' target='_blank'><b>OpenAI</b></a> to recoginze the speech and ECAPA-TDNN model from <a href='https://github.com/speechbrain/speechbrain' target='_blank'><b>SpeechBrain</b></a> to encode and clasify speakers</h2>
|
318 |
+
</div>
|
319 |
+
''')
|
320 |
+
|
321 |
+
with gr.Row():
|
322 |
+
gr.Markdown('''
|
323 |
+
### Transcribe youtube link using OpenAI Whisper
|
324 |
+
##### 1. Using Open AI's Whisper model to seperate audio into segments and generate transcripts.
|
325 |
+
##### 2. Generating speaker embeddings for each segments.
|
326 |
+
##### 3. Applying agglomerative clustering on the embeddings to identify the speaker for each segment.
|
327 |
+
''')
|
328 |
+
|
329 |
+
with gr.Row():
|
330 |
+
gr.Markdown('''
|
331 |
+
### You can test by following examples:
|
332 |
+
''')
|
333 |
+
examples = gr.Examples(examples=
|
334 |
+
[ "https://www.youtube.com/watch?v=j7BfEzAFuYc&t=32s",
|
335 |
+
"https://www.youtube.com/watch?v=-UX0X45sYe4",
|
336 |
+
"https://www.youtube.com/watch?v=7minSgqi-Gw"],
|
337 |
+
label="Examples", inputs=[youtube_url_in])
|
338 |
+
|
339 |
+
|
340 |
+
with gr.Row():
|
341 |
+
with gr.Column():
|
342 |
+
youtube_url_in.render()
|
343 |
+
download_youtube_btn = gr.Button("Download Youtube video")
|
344 |
+
download_youtube_btn.click(get_youtube, [youtube_url_in], [
|
345 |
+
video_in])
|
346 |
+
print(video_in)
|
347 |
+
|
348 |
+
|
349 |
+
with gr.Row():
|
350 |
+
with gr.Column():
|
351 |
+
video_in.render()
|
352 |
+
with gr.Column():
|
353 |
+
gr.Markdown('''
|
354 |
+
##### Here you can start the transcription process.
|
355 |
+
##### Please select the source language for transcription.
|
356 |
+
##### You should select a number of speakers for getting better results.
|
357 |
+
''')
|
358 |
+
selected_source_lang.render()
|
359 |
+
selected_whisper_model.render()
|
360 |
+
number_speakers.render()
|
361 |
+
transcribe_btn = gr.Button("Transcribe audio and diarization")
|
362 |
+
transcribe_btn.click(speech_to_text, [video_in, selected_source_lang, selected_whisper_model, number_speakers], [transcription_df, system_info])
|
363 |
+
|
364 |
+
|
365 |
+
with gr.Row():
|
366 |
+
gr.Markdown('''
|
367 |
+
##### Here you will get transcription output
|
368 |
+
##### ''')
|
369 |
+
|
370 |
+
|
371 |
+
with gr.Row():
|
372 |
+
with gr.Column():
|
373 |
+
transcription_df.render()
|
374 |
+
system_info.render()
|
375 |
+
gr.Markdown('''<center><img src='https://visitor-badge.glitch.me/badge?page_id=WhisperDiarizationSpeakers' alt='visitor badge'></center>''')
|
376 |
+
|
377 |
+
with gr.Tab("Whisper Transcribe Japanese Audio"):
|
378 |
+
gr.Markdown(f'''
|
379 |
+
<div>
|
380 |
+
<h1 style='text-align: center'>Whisper Transcribe Japanese Audio</h1>
|
381 |
+
</div>
|
382 |
+
Transcribe long-form microphone or audio inputs with the click of a button! The fine-tuned
|
383 |
+
checkpoint <a href='https://huggingface.co/{MODEL_NAME}' target='_blank'><b>{MODEL_NAME}</b></a> to transcribe audio files of arbitrary length.
|
384 |
+
''')
|
385 |
+
microphone = gr.inputs.Audio(source="microphone", type="filepath", optional=True)
|
386 |
+
upload = gr.inputs.Audio(source="upload", type="filepath", optional=True)
|
387 |
+
transcribe_btn = gr.Button("Transcribe Audio")
|
388 |
+
text_output = gr.Textbox()
|
389 |
+
with gr.Row():
|
390 |
+
gr.Markdown('''
|
391 |
+
### You can test by following examples:
|
392 |
+
''')
|
393 |
+
examples = gr.Examples(examples=
|
394 |
+
[ "sample1.wav",
|
395 |
+
"sample2.wav",
|
396 |
+
],
|
397 |
+
label="Examples", inputs=[upload])
|
398 |
+
transcribe_btn.click(transcribe, [microphone, upload], outputs=text_output)
|
399 |
+
|
400 |
+
with gr.Tab("Whisper Transcribe Japanese YouTube"):
|
401 |
+
gr.Markdown(f'''
|
402 |
+
<div>
|
403 |
+
<h1 style='text-align: center'>Whisper Transcribe Japanese YouTube</h1>
|
404 |
+
</div>
|
405 |
+
Transcribe long-form YouTube videos with the click of a button! The fine-tuned checkpoint:
|
406 |
+
<a href='https://huggingface.co/{MODEL_NAME}' target='_blank'><b>{MODEL_NAME}</b></a> to transcribe audio files of arbitrary length.
|
407 |
+
''')
|
408 |
+
youtube_link = gr.Textbox(label="Youtube url", lines=1, interactive=True)
|
409 |
+
yt_transcribe_btn = gr.Button("Transcribe YouTube")
|
410 |
+
text_output2 = gr.Textbox()
|
411 |
+
html_output = gr.Markdown()
|
412 |
+
yt_transcribe_btn.click(yt_transcribe, [youtube_link], outputs=[html_output, text_output2])
|
413 |
+
|
414 |
+
demo.launch(debug=True)
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ffmpeg
|
requirements.txt
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/transformers
|
2 |
+
git+https://github.com/pyannote/pyannote-audio
|
3 |
+
git+https://github.com/openai/whisper.git
|
4 |
+
gradio==3.12
|
5 |
+
ffmpeg-python
|
6 |
+
pandas==1.5.0
|
7 |
+
pytube==12.1.0
|
8 |
+
sacremoses
|
9 |
+
sentencepiece
|
10 |
+
tokenizers
|
11 |
+
torch
|
12 |
+
torchaudio
|
13 |
+
tqdm==4.64.1
|
14 |
+
EasyNMT==2.0.2
|
15 |
+
tqdm
|
16 |
+
nltk
|
17 |
+
transformers
|
18 |
+
pysrt
|
19 |
+
psutil==5.9.2
|
20 |
+
requests
|
21 |
+
gpuinfo
|
sample1.wav
ADDED
Binary file (306 kB). View file
|
|
sample2.wav
ADDED
Binary file (470 kB). View file
|
|