Spaces:
Sleeping
Sleeping
Update audio_to_text_tool.py
Browse files- audio_to_text_tool.py +8 -6
audio_to_text_tool.py
CHANGED
@@ -64,19 +64,17 @@ def audio_to_text_from_youtube(youtube_url: str) -> str:
|
|
64 |
"""
|
65 |
try:
|
66 |
with tempfile.TemporaryDirectory() as tmpdir:
|
67 |
-
|
|
|
68 |
|
69 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
70 |
cookies_path = os.path.join(BASE_DIR, 'files', 'cookies.txt')
|
71 |
|
72 |
-
|
73 |
|
74 |
-
print('cookies: \n' + plain_txt_file)
|
75 |
-
|
76 |
-
# Download best audio using yt-dlp
|
77 |
ydl_opts = {
|
78 |
"format": "bestaudio/best",
|
79 |
-
"outtmpl":
|
80 |
"quiet": True,
|
81 |
"cookiefile": cookies_path,
|
82 |
"postprocessors": [{
|
@@ -89,6 +87,10 @@ def audio_to_text_from_youtube(youtube_url: str) -> str:
|
|
89 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
90 |
ydl.download([youtube_url])
|
91 |
|
|
|
|
|
|
|
|
|
92 |
# Transcribe with OpenAI Whisper
|
93 |
with open(audio_output_path, "rb") as audio_file:
|
94 |
transcript = client.audio.transcriptions.create(
|
|
|
64 |
"""
|
65 |
try:
|
66 |
with tempfile.TemporaryDirectory() as tmpdir:
|
67 |
+
audio_stem = os.path.join(tmpdir, "audio")
|
68 |
+
audio_output_path = audio_stem + ".mp3"
|
69 |
|
70 |
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
71 |
cookies_path = os.path.join(BASE_DIR, 'files', 'cookies.txt')
|
72 |
|
73 |
+
print('cookies: \n' + get_text_file_contents(cookies_path))
|
74 |
|
|
|
|
|
|
|
75 |
ydl_opts = {
|
76 |
"format": "bestaudio/best",
|
77 |
+
"outtmpl": audio_stem,
|
78 |
"quiet": True,
|
79 |
"cookiefile": cookies_path,
|
80 |
"postprocessors": [{
|
|
|
87 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
88 |
ydl.download([youtube_url])
|
89 |
|
90 |
+
# Ensure file exists
|
91 |
+
if not os.path.exists(audio_output_path):
|
92 |
+
raise FileNotFoundError(f"Audio file not created: {audio_output_path}")
|
93 |
+
|
94 |
# Transcribe with OpenAI Whisper
|
95 |
with open(audio_output_path, "rb") as audio_file:
|
96 |
transcript = client.audio.transcriptions.create(
|