Spaces:
Sleeping
Sleeping
SevenhuijsenM
commited on
Commit
·
c1e7ebb
1
Parent(s):
00c3c4f
Attempt for video url
Browse files
app.py
CHANGED
@@ -12,22 +12,30 @@ def download_audio(url, output_path='downloads'):
|
|
12 |
|
13 |
# Get the audio stream with the highest quality
|
14 |
audio_stream = yt.streams.filter(only_audio=True, file_extension='mp4').first()
|
15 |
-
|
16 |
-
# Set the output path (default: 'downloads' folder in the current directory)
|
17 |
audio_stream.download(output_path)
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
os.rename(mp4_path, mp3_path)
|
25 |
|
26 |
-
|
27 |
-
|
28 |
|
|
|
29 |
# Use the model to transcribe the audio
|
30 |
text = pipe(mp3_path)["text"]
|
|
|
|
|
|
|
31 |
|
32 |
return text
|
33 |
except Exception as e:
|
|
|
12 |
|
13 |
# Get the audio stream with the highest quality
|
14 |
audio_stream = yt.streams.filter(only_audio=True, file_extension='mp4').first()
|
|
|
|
|
15 |
audio_stream.download(output_path)
|
16 |
+
print(f"Downloaded audio to {output_path}")
|
17 |
+
|
18 |
+
# If a video.mp4 file already exists, delete it
|
19 |
+
if os.path.exists(f"{output_path}/video.mp4"):
|
20 |
+
os.remove(f"{output_path}/video.mp4")
|
21 |
|
22 |
+
print("Downloading video...")
|
23 |
+
|
24 |
+
# Change the name of the file to video.mp4
|
25 |
+
default_filename = audio_stream.default_filename
|
26 |
+
mp4_path = f"{output_path}/{default_filename}"
|
27 |
+
mp3_path = f"{output_path}/video.mp3"
|
28 |
os.rename(mp4_path, mp3_path)
|
29 |
|
30 |
+
print("Downloaded video")
|
31 |
+
|
32 |
|
33 |
+
print("Transcribing audio...")
|
34 |
# Use the model to transcribe the audio
|
35 |
text = pipe(mp3_path)["text"]
|
36 |
+
print(f"Transcribed audio: {text}")
|
37 |
+
# Delete the audio file
|
38 |
+
os.remove(mp3_path)
|
39 |
|
40 |
return text
|
41 |
except Exception as e:
|