Update utils/audio_processing.py
Browse files- utils/audio_processing.py +10 -8
utils/audio_processing.py
CHANGED
@@ -10,8 +10,16 @@ import uuid
|
|
10 |
AudioSegment.converter = shutil.which("ffmpeg")
|
11 |
|
12 |
# -------------------------------
|
13 |
-
#
|
14 |
# -------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def download_audio_as_wav(url, max_filesize_mb=70):
|
16 |
"""
|
17 |
Downloads audio from a URL using yt-dlp, then converts it to WAV using ffmpeg.
|
@@ -32,12 +40,6 @@ def download_audio_as_wav(url, max_filesize_mb=70):
|
|
32 |
if not cookies_b64:
|
33 |
raise EnvironmentError("cookies environment variable not set.")
|
34 |
|
35 |
-
def safe_base64_decode(data):
|
36 |
-
# Fix padding if necessary
|
37 |
-
missing_padding = len(data) % 4
|
38 |
-
if missing_padding:
|
39 |
-
data += "=" * (4 - missing_padding)
|
40 |
-
return base64.b64decode(data)
|
41 |
# Decode and write cookies.txt
|
42 |
with open(temp_cookie_path, "wb") as f:
|
43 |
f.write(safe_base64_decode(cookies_b64))
|
@@ -94,7 +96,7 @@ def download_audio_as_wav(url, max_filesize_mb=70):
|
|
94 |
|
95 |
|
96 |
# --------------------------
|
97 |
-
#
|
98 |
# --------------------------
|
99 |
def trim_audio(input_wav_path, max_duration_sec=120):
|
100 |
"""
|
|
|
10 |
AudioSegment.converter = shutil.which("ffmpeg")
|
11 |
|
12 |
# -------------------------------
|
13 |
+
# Download audio from a Video url
|
14 |
# -------------------------------
|
15 |
+
|
16 |
+
def safe_base64_decode(data):
|
17 |
+
# Fix padding if necessary
|
18 |
+
missing_padding = len(data) % 4
|
19 |
+
if missing_padding:
|
20 |
+
data += "=" * (4 - missing_padding)
|
21 |
+
return base64.b64decode(data)
|
22 |
+
|
23 |
def download_audio_as_wav(url, max_filesize_mb=70):
|
24 |
"""
|
25 |
Downloads audio from a URL using yt-dlp, then converts it to WAV using ffmpeg.
|
|
|
40 |
if not cookies_b64:
|
41 |
raise EnvironmentError("cookies environment variable not set.")
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# Decode and write cookies.txt
|
44 |
with open(temp_cookie_path, "wb") as f:
|
45 |
f.write(safe_base64_decode(cookies_b64))
|
|
|
96 |
|
97 |
|
98 |
# --------------------------
|
99 |
+
# Trim audios to 2 minutes
|
100 |
# --------------------------
|
101 |
def trim_audio(input_wav_path, max_duration_sec=120):
|
102 |
"""
|