Commit ·
0d5259c
0
Parent(s):
Duplicate from nanomenta/Whisper_speaker_diarization
Browse files- .gitattributes +34 -0
- README.md +15 -0
- app.py +338 -0
- packages.txt +1 -0
- requirements.txt +20 -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: nanomenta/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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 |
+
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 |
+
from sklearn.metrics import silhouette_score
|
| 13 |
+
|
| 14 |
+
from pytube import YouTube
|
| 15 |
+
import torch
|
| 16 |
+
import pyannote.audio
|
| 17 |
+
from pyannote.audio.pipelines.speaker_verification import PretrainedSpeakerEmbedding
|
| 18 |
+
from pyannote.audio import Audio
|
| 19 |
+
from pyannote.core import Segment
|
| 20 |
+
|
| 21 |
+
from gpuinfo import GPUInfo
|
| 22 |
+
|
| 23 |
+
import wave
|
| 24 |
+
import contextlib
|
| 25 |
+
from transformers import pipeline
|
| 26 |
+
import psutil
|
| 27 |
+
|
| 28 |
+
whisper_models = ["base", "small", "medium", "large"]
|
| 29 |
+
source_languages = {
|
| 30 |
+
"en": "English",
|
| 31 |
+
"zh": "Chinese",
|
| 32 |
+
"de": "German",
|
| 33 |
+
"es": "Spanish",
|
| 34 |
+
"ru": "Russian",
|
| 35 |
+
"ko": "Korean",
|
| 36 |
+
"fr": "French",
|
| 37 |
+
"ja": "Japanese",
|
| 38 |
+
"pt": "Portuguese",
|
| 39 |
+
"tr": "Turkish",
|
| 40 |
+
"pl": "Polish",
|
| 41 |
+
"ca": "Catalan",
|
| 42 |
+
"nl": "Dutch",
|
| 43 |
+
"ar": "Arabic",
|
| 44 |
+
"sv": "Swedish",
|
| 45 |
+
"it": "Italian",
|
| 46 |
+
"id": "Indonesian",
|
| 47 |
+
"hi": "Hindi",
|
| 48 |
+
"fi": "Finnish",
|
| 49 |
+
"vi": "Vietnamese",
|
| 50 |
+
"he": "Hebrew",
|
| 51 |
+
"uk": "Ukrainian",
|
| 52 |
+
"el": "Greek",
|
| 53 |
+
"ms": "Malay",
|
| 54 |
+
"cs": "Czech",
|
| 55 |
+
"ro": "Romanian",
|
| 56 |
+
"da": "Danish",
|
| 57 |
+
"hu": "Hungarian",
|
| 58 |
+
"ta": "Tamil",
|
| 59 |
+
"no": "Norwegian",
|
| 60 |
+
"th": "Thai",
|
| 61 |
+
"ur": "Urdu",
|
| 62 |
+
"hr": "Croatian",
|
| 63 |
+
"bg": "Bulgarian",
|
| 64 |
+
"lt": "Lithuanian",
|
| 65 |
+
"la": "Latin",
|
| 66 |
+
"mi": "Maori",
|
| 67 |
+
"ml": "Malayalam",
|
| 68 |
+
"cy": "Welsh",
|
| 69 |
+
"sk": "Slovak",
|
| 70 |
+
"te": "Telugu",
|
| 71 |
+
"fa": "Persian",
|
| 72 |
+
"lv": "Latvian",
|
| 73 |
+
"bn": "Bengali",
|
| 74 |
+
"sr": "Serbian",
|
| 75 |
+
"az": "Azerbaijani",
|
| 76 |
+
"sl": "Slovenian",
|
| 77 |
+
"kn": "Kannada",
|
| 78 |
+
"et": "Estonian",
|
| 79 |
+
"mk": "Macedonian",
|
| 80 |
+
"br": "Breton",
|
| 81 |
+
"eu": "Basque",
|
| 82 |
+
"is": "Icelandic",
|
| 83 |
+
"hy": "Armenian",
|
| 84 |
+
"ne": "Nepali",
|
| 85 |
+
"mn": "Mongolian",
|
| 86 |
+
"bs": "Bosnian",
|
| 87 |
+
"kk": "Kazakh",
|
| 88 |
+
"sq": "Albanian",
|
| 89 |
+
"sw": "Swahili",
|
| 90 |
+
"gl": "Galician",
|
| 91 |
+
"mr": "Marathi",
|
| 92 |
+
"pa": "Punjabi",
|
| 93 |
+
"si": "Sinhala",
|
| 94 |
+
"km": "Khmer",
|
| 95 |
+
"sn": "Shona",
|
| 96 |
+
"yo": "Yoruba",
|
| 97 |
+
"so": "Somali",
|
| 98 |
+
"af": "Afrikaans",
|
| 99 |
+
"oc": "Occitan",
|
| 100 |
+
"ka": "Georgian",
|
| 101 |
+
"be": "Belarusian",
|
| 102 |
+
"tg": "Tajik",
|
| 103 |
+
"sd": "Sindhi",
|
| 104 |
+
"gu": "Gujarati",
|
| 105 |
+
"am": "Amharic",
|
| 106 |
+
"yi": "Yiddish",
|
| 107 |
+
"lo": "Lao",
|
| 108 |
+
"uz": "Uzbek",
|
| 109 |
+
"fo": "Faroese",
|
| 110 |
+
"ht": "Haitian creole",
|
| 111 |
+
"ps": "Pashto",
|
| 112 |
+
"tk": "Turkmen",
|
| 113 |
+
"nn": "Nynorsk",
|
| 114 |
+
"mt": "Maltese",
|
| 115 |
+
"sa": "Sanskrit",
|
| 116 |
+
"lb": "Luxembourgish",
|
| 117 |
+
"my": "Myanmar",
|
| 118 |
+
"bo": "Tibetan",
|
| 119 |
+
"tl": "Tagalog",
|
| 120 |
+
"mg": "Malagasy",
|
| 121 |
+
"as": "Assamese",
|
| 122 |
+
"tt": "Tatar",
|
| 123 |
+
"haw": "Hawaiian",
|
| 124 |
+
"ln": "Lingala",
|
| 125 |
+
"ha": "Hausa",
|
| 126 |
+
"ba": "Bashkir",
|
| 127 |
+
"jw": "Javanese",
|
| 128 |
+
"su": "Sundanese",
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
source_language_list = [key[0] for key in source_languages.items()]
|
| 132 |
+
|
| 133 |
+
os.makedirs('output', exist_ok=True)
|
| 134 |
+
|
| 135 |
+
embedding_model = PretrainedSpeakerEmbedding(
|
| 136 |
+
"speechbrain/spkrec-ecapa-voxceleb",
|
| 137 |
+
device=torch.device("cuda" if torch.cuda.is_available() else "cpu"))
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def convert_time(secs):
|
| 142 |
+
return datetime.timedelta(seconds=round(secs))
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def speech_to_text(audio_file_path, selected_source_lang, whisper_model, num_speakers):
|
| 147 |
+
"""
|
| 148 |
+
# Transcribe youtube link using OpenAI Whisper
|
| 149 |
+
1. Using Open AI's Whisper model to seperate audio into segments and generate transcripts.
|
| 150 |
+
2. Generating speaker embeddings for each segments.
|
| 151 |
+
3. Applying agglomerative clustering on the embeddings to identify the speaker for each segment.
|
| 152 |
+
|
| 153 |
+
Speech Recognition is based on models from OpenAI Whisper https://github.com/openai/whisper
|
| 154 |
+
Speaker diarization model and pipeline from by https://github.com/pyannote/pyannote-audio
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
model = whisper.load_model(whisper_model)
|
| 158 |
+
time_start = time.time()
|
| 159 |
+
if(audio_file_path == None):
|
| 160 |
+
raise ValueError("Error no audio input")
|
| 161 |
+
print(audio_file_path)
|
| 162 |
+
|
| 163 |
+
try:
|
| 164 |
+
# Read and convert youtube video
|
| 165 |
+
#_,file_ending = os.path.splitext(f'{video_file_path}')
|
| 166 |
+
#print(f'file enging is {file_ending}')
|
| 167 |
+
#audio_file = video_file_path.replace(file_ending, ".wav")
|
| 168 |
+
#print("starting conversion to wav")
|
| 169 |
+
#os.system(f'ffmpeg -i "{video_file_path}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
|
| 170 |
+
|
| 171 |
+
audio_file = audio_file_path
|
| 172 |
+
|
| 173 |
+
# Get duration
|
| 174 |
+
with contextlib.closing(wave.open(audio_file,'r')) as f:
|
| 175 |
+
frames = f.getnframes()
|
| 176 |
+
rate = f.getframerate()
|
| 177 |
+
duration = frames / float(rate)
|
| 178 |
+
print(f"conversion to wav ready, duration of audio file: {duration}")
|
| 179 |
+
|
| 180 |
+
# Transcribe audio
|
| 181 |
+
options = dict(language=selected_source_lang, beam_size=5, best_of=5)
|
| 182 |
+
transcribe_options = dict(task="transcribe", **options)
|
| 183 |
+
result = model.transcribe(audio_file, **transcribe_options)
|
| 184 |
+
segments = result["segments"]
|
| 185 |
+
print("starting whisper done with whisper")
|
| 186 |
+
except Exception as e:
|
| 187 |
+
raise RuntimeError("Error converting video to audio")
|
| 188 |
+
|
| 189 |
+
try:
|
| 190 |
+
# Create embedding
|
| 191 |
+
def segment_embedding(segment):
|
| 192 |
+
audio = Audio()
|
| 193 |
+
start = segment["start"]
|
| 194 |
+
# Whisper overshoots the end timestamp in the last segment
|
| 195 |
+
end = min(duration, segment["end"])
|
| 196 |
+
clip = Segment(start, end)
|
| 197 |
+
waveform, sample_rate = audio.crop(audio_file, clip)
|
| 198 |
+
return embedding_model(waveform[None])
|
| 199 |
+
|
| 200 |
+
embeddings = np.zeros(shape=(len(segments), 192))
|
| 201 |
+
for i, segment in enumerate(segments):
|
| 202 |
+
embeddings[i] = segment_embedding(segment)
|
| 203 |
+
embeddings = np.nan_to_num(embeddings)
|
| 204 |
+
print(f'Embedding shape: {embeddings.shape}')
|
| 205 |
+
|
| 206 |
+
if num_speakers == 0:
|
| 207 |
+
# Find the best number of speakers
|
| 208 |
+
score_num_speakers = {}
|
| 209 |
+
|
| 210 |
+
for num_speakers in range(2, 10+1):
|
| 211 |
+
clustering = AgglomerativeClustering(num_speakers).fit(embeddings)
|
| 212 |
+
score = silhouette_score(embeddings, clustering.labels_, metric='euclidean')
|
| 213 |
+
score_num_speakers[num_speakers] = score
|
| 214 |
+
best_num_speaker = max(score_num_speakers, key=lambda x:score_num_speakers[x])
|
| 215 |
+
print(f"The best number of speakers: {best_num_speaker} with {score_num_speakers[best_num_speaker]} score")
|
| 216 |
+
else:
|
| 217 |
+
best_num_speaker = num_speakers
|
| 218 |
+
|
| 219 |
+
# Assign speaker label
|
| 220 |
+
clustering = AgglomerativeClustering(best_num_speaker).fit(embeddings)
|
| 221 |
+
labels = clustering.labels_
|
| 222 |
+
for i in range(len(segments)):
|
| 223 |
+
segments[i]["speaker"] = 'SPEAKER ' + str(labels[i] + 1)
|
| 224 |
+
|
| 225 |
+
# Make output
|
| 226 |
+
objects = {
|
| 227 |
+
'Start' : [],
|
| 228 |
+
'End': [],
|
| 229 |
+
'Speaker': [],
|
| 230 |
+
'Text': []
|
| 231 |
+
}
|
| 232 |
+
text = ''
|
| 233 |
+
for (i, segment) in enumerate(segments):
|
| 234 |
+
if i == 0 or segments[i - 1]["speaker"] != segment["speaker"]:
|
| 235 |
+
objects['Start'].append(str(convert_time(segment["start"])))
|
| 236 |
+
objects['Speaker'].append(segment["speaker"])
|
| 237 |
+
if i != 0:
|
| 238 |
+
objects['End'].append(str(convert_time(segments[i - 1]["end"])))
|
| 239 |
+
objects['Text'].append(text)
|
| 240 |
+
text = ''
|
| 241 |
+
text += segment["text"] + ' '
|
| 242 |
+
objects['End'].append(str(convert_time(segments[i - 1]["end"])))
|
| 243 |
+
objects['Text'].append(text)
|
| 244 |
+
|
| 245 |
+
time_end = time.time()
|
| 246 |
+
time_diff = time_end - time_start
|
| 247 |
+
memory = psutil.virtual_memory()
|
| 248 |
+
gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
|
| 249 |
+
gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
|
| 250 |
+
gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
|
| 251 |
+
system_info = f"""
|
| 252 |
+
*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
|
| 253 |
+
*Processing time: {time_diff:.5} seconds.*
|
| 254 |
+
*GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}MiB.*
|
| 255 |
+
"""
|
| 256 |
+
save_path = "output/transcript_result.csv"
|
| 257 |
+
df_results = pd.DataFrame(objects)
|
| 258 |
+
df_results.to_csv(save_path)
|
| 259 |
+
return df_results, system_info, save_path
|
| 260 |
+
|
| 261 |
+
except Exception as e:
|
| 262 |
+
raise RuntimeError("Error Running inference with local model", e)
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
# ---- Gradio Layout -----
|
| 266 |
+
# Inspiration from https://huggingface.co/spaces/RASMUS/Whisper-youtube-crosslingual-subtitles
|
| 267 |
+
audio_in = gr.Audio(label="Audio file", type="filepath", source="upload")
|
| 268 |
+
|
| 269 |
+
df_init = pd.DataFrame(columns=['Start', 'End', 'Speaker', 'Text'])
|
| 270 |
+
memory = psutil.virtual_memory()
|
| 271 |
+
selected_source_lang = gr.Dropdown(choices=source_language_list, type="value", value="en", label="Spoken language in audio", interactive=True)
|
| 272 |
+
selected_whisper_model = gr.Dropdown(choices=whisper_models, type="value", value="base", label="Selected Whisper model", interactive=True)
|
| 273 |
+
number_speakers = gr.Number(precision=0, value=0, label="Input number of speakers for better results. If value=0, model will automatic find the best number of speakers", interactive=True)
|
| 274 |
+
system_info = gr.Markdown(f"*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB*")
|
| 275 |
+
download_transcript = gr.File(label="Download transcript")
|
| 276 |
+
transcription_df = gr.DataFrame(value=df_init,label="Transcription dataframe", row_count=(0, "dynamic"), max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
|
| 277 |
+
title = "Whisper speaker diarization"
|
| 278 |
+
demo = gr.Blocks(title=title)
|
| 279 |
+
demo.encrypt = False
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
with demo:
|
| 283 |
+
with gr.Tab("Whisper speaker diarization"):
|
| 284 |
+
gr.Markdown('''
|
| 285 |
+
<div>
|
| 286 |
+
<h1 style='text-align: center'>Whisper speaker diarization</h1>
|
| 287 |
+
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>
|
| 288 |
+
</div>
|
| 289 |
+
''')
|
| 290 |
+
|
| 291 |
+
with gr.Row():
|
| 292 |
+
gr.Markdown('''
|
| 293 |
+
### Transcribe audio files using OpenAI Whisper
|
| 294 |
+
##### 1. Using Open AI's Whisper model to seperate audio into segments and generate transcripts.
|
| 295 |
+
##### 2. Generating speaker embeddings for each segments.
|
| 296 |
+
##### 3. Applying agglomerative clustering on the embeddings to identify the speaker for each segment.
|
| 297 |
+
''')
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
with gr.Row():
|
| 304 |
+
with gr.Column():
|
| 305 |
+
audio_in.render()
|
| 306 |
+
with gr.Column():
|
| 307 |
+
gr.Markdown('''
|
| 308 |
+
##### Here you can start the transcription process.
|
| 309 |
+
##### Please select the source language for transcription.
|
| 310 |
+
##### You can select a range of assumed numbers of speakers.
|
| 311 |
+
''')
|
| 312 |
+
selected_source_lang.render()
|
| 313 |
+
selected_whisper_model.render()
|
| 314 |
+
number_speakers.render()
|
| 315 |
+
transcribe_btn = gr.Button("Transcribe audio and diarization")
|
| 316 |
+
transcribe_btn.click(speech_to_text,
|
| 317 |
+
[audio_in, selected_source_lang, selected_whisper_model, number_speakers],
|
| 318 |
+
[transcription_df, system_info, download_transcript]
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
with gr.Row():
|
| 322 |
+
gr.Markdown('''
|
| 323 |
+
##### Here you will get transcription output
|
| 324 |
+
##### ''')
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
with gr.Row():
|
| 328 |
+
with gr.Column():
|
| 329 |
+
download_transcript.render()
|
| 330 |
+
transcription_df.render()
|
| 331 |
+
system_info.render()
|
| 332 |
+
gr.Markdown('''<center><img src='https://visitor-badge.glitch.me/badge?page_id=WhisperDiarizationSpeakers' alt='visitor badge'><a href="https://opensource.org/licenses/Apache-2.0"><img src='https://img.shields.io/badge/License-Apache_2.0-blue.svg' alt='License: Apache 2.0'></center>''')
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
demo.launch(debug=True)
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
requirements.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
nltk
|
| 16 |
+
transformers
|
| 17 |
+
pysrt
|
| 18 |
+
psutil==5.9.2
|
| 19 |
+
requests
|
| 20 |
+
gpuinfo
|
sample1.wav
ADDED
|
Binary file (306 kB). View file
|
|
|
sample2.wav
ADDED
|
Binary file (470 kB). View file
|
|
|