Spaces:
Runtime error
Runtime error
Commit
•
e5dbd61
1
Parent(s):
f999e80
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@ def Transcribe(audio="temp_audio.wav"):
|
|
22 |
spl = timeStr.split(":")
|
23 |
s = (int)((int(spl[0]) * 60 * 60 + int(spl[1]) * 60 + float(spl[2]) )* 1000)
|
24 |
return s
|
|
|
25 |
def preprocess(audio):
|
26 |
t1 = 0 * 1000
|
27 |
t2 = 20 * 60 * 1000
|
@@ -32,6 +33,7 @@ def Transcribe(audio="temp_audio.wav"):
|
|
32 |
newAudio = spacer.append(a, crossfade=0)
|
33 |
newAudio.export(audio, format="wav")
|
34 |
return spacermilli, spacer
|
|
|
35 |
def diarization(audio):
|
36 |
as_audio = AudioSegment.from_wav(audio)
|
37 |
DEMO_FILE = {'uri': 'blabal', 'audio': audio}
|
@@ -109,31 +111,37 @@ def VideoTranscribe(video):
|
|
109 |
subprocess.call(command, shell=True)
|
110 |
return Transcribe()
|
111 |
|
112 |
-
def YoutubeTranscribe(
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
138 |
with gr.Blocks() as i:
|
139 |
video = gr.Video()
|
|
|
22 |
spl = timeStr.split(":")
|
23 |
s = (int)((int(spl[0]) * 60 * 60 + int(spl[1]) * 60 + float(spl[2]) )* 1000)
|
24 |
return s
|
25 |
+
|
26 |
def preprocess(audio):
|
27 |
t1 = 0 * 1000
|
28 |
t2 = 20 * 60 * 1000
|
|
|
33 |
newAudio = spacer.append(a, crossfade=0)
|
34 |
newAudio.export(audio, format="wav")
|
35 |
return spacermilli, spacer
|
36 |
+
|
37 |
def diarization(audio):
|
38 |
as_audio = AudioSegment.from_wav(audio)
|
39 |
DEMO_FILE = {'uri': 'blabal', 'audio': audio}
|
|
|
111 |
subprocess.call(command, shell=True)
|
112 |
return Transcribe()
|
113 |
|
114 |
+
def YoutubeTranscribe(URL, retries = 5):
|
115 |
+
if retries:
|
116 |
+
if "youtu" not in URL.lower():
|
117 |
+
raise Exception(f"{url} is not a valid youtube URL.")
|
118 |
+
else:
|
119 |
+
try:
|
120 |
+
os.remove("temp_audio.wav")
|
121 |
+
except OSError:
|
122 |
+
pass
|
123 |
+
ydl_opts = {
|
124 |
+
'format': 'bestaudio/best',
|
125 |
+
'outtmpl': 'temp_audio.%(ext)s',
|
126 |
+
'postprocessors': [{
|
127 |
+
'key': 'FFmpegExtractAudio',
|
128 |
+
'preferredcodec': 'wav',
|
129 |
+
}],
|
130 |
+
}
|
131 |
+
try:
|
132 |
+
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
133 |
+
ydl.download([url])
|
134 |
+
except:
|
135 |
+
return YoutubeTranscribe(url, retries-1)
|
136 |
+
stream = ffmpeg.input('temp_audio.m4a')
|
137 |
+
stream = ffmpeg.output(stream, 'temp_audio.wav')
|
138 |
+
try:
|
139 |
+
os.remove("temp_audio.m4a")
|
140 |
+
except OSError:
|
141 |
+
pass
|
142 |
+
return Transcribe()
|
143 |
+
else:
|
144 |
+
raise Exception(f"Unable to get video from {url}")
|
145 |
|
146 |
with gr.Blocks() as i:
|
147 |
video = gr.Video()
|