Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from detect import SimpleOfflineAccentClassifier
|
|
3 |
import yt_dlp
|
4 |
import os
|
5 |
import subprocess
|
|
|
6 |
|
7 |
# FFmpeg kurulumu
|
8 |
def install_ffmpeg():
|
@@ -17,13 +18,17 @@ install_ffmpeg()
|
|
17 |
|
18 |
def download_youtube_audio(url):
|
19 |
try:
|
|
|
|
|
|
|
|
|
20 |
ydl_opts = {
|
21 |
'format': 'bestaudio/best',
|
22 |
'postprocessors': [{
|
23 |
'key': 'FFmpegExtractAudio',
|
24 |
'preferredcodec': 'wav',
|
25 |
}],
|
26 |
-
'outtmpl': '
|
27 |
'quiet': True,
|
28 |
'no_warnings': True
|
29 |
}
|
@@ -31,21 +36,21 @@ def download_youtube_audio(url):
|
|
31 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
32 |
ydl.download([url])
|
33 |
|
34 |
-
return
|
35 |
except Exception as e:
|
36 |
print(f"YouTube download error: {e}")
|
37 |
return None
|
38 |
|
39 |
def analyze_audio(audio_file, youtube_url):
|
40 |
-
if youtube_url:
|
41 |
-
audio_file = download_youtube_audio(youtube_url)
|
42 |
-
if not audio_file:
|
43 |
-
return "Failed to download YouTube audio. Please check the URL and try again."
|
44 |
-
|
45 |
-
if not audio_file:
|
46 |
-
return "Please upload an audio file or provide a YouTube URL."
|
47 |
-
|
48 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
classifier = SimpleOfflineAccentClassifier()
|
50 |
result = classifier.predict_accent(audio_file)
|
51 |
|
|
|
3 |
import yt_dlp
|
4 |
import os
|
5 |
import subprocess
|
6 |
+
import tempfile
|
7 |
|
8 |
# FFmpeg kurulumu
|
9 |
def install_ffmpeg():
|
|
|
18 |
|
19 |
def download_youtube_audio(url):
|
20 |
try:
|
21 |
+
# Geçici dosya yolu oluştur
|
22 |
+
temp_dir = tempfile.gettempdir()
|
23 |
+
temp_file = os.path.join(temp_dir, 'temp_audio.wav')
|
24 |
+
|
25 |
ydl_opts = {
|
26 |
'format': 'bestaudio/best',
|
27 |
'postprocessors': [{
|
28 |
'key': 'FFmpegExtractAudio',
|
29 |
'preferredcodec': 'wav',
|
30 |
}],
|
31 |
+
'outtmpl': temp_file.replace('.wav', ''),
|
32 |
'quiet': True,
|
33 |
'no_warnings': True
|
34 |
}
|
|
|
36 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
37 |
ydl.download([url])
|
38 |
|
39 |
+
return temp_file
|
40 |
except Exception as e:
|
41 |
print(f"YouTube download error: {e}")
|
42 |
return None
|
43 |
|
44 |
def analyze_audio(audio_file, youtube_url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
try:
|
46 |
+
if youtube_url:
|
47 |
+
audio_file = download_youtube_audio(youtube_url)
|
48 |
+
if not audio_file:
|
49 |
+
return "Failed to download YouTube audio. Please check the URL and try again."
|
50 |
+
|
51 |
+
if not audio_file:
|
52 |
+
return "Please upload an audio file or provide a YouTube URL."
|
53 |
+
|
54 |
classifier = SimpleOfflineAccentClassifier()
|
55 |
result = classifier.predict_accent(audio_file)
|
56 |
|