Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,20 +26,37 @@ def get_font_path():
|
|
| 26 |
return font
|
| 27 |
return None # Fallback: FFmpeg soll selbst suchen (klappt manchmal nicht)
|
| 28 |
|
| 29 |
-
def save_temp_audio(
|
| 30 |
-
"""
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Rückgabe des Verzeichnisses, das später gelöscht werden kann, und des Dateipfads
|
| 41 |
return temp_audio_dir, temp_audio
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
def create_timed_drawtext(word, start_time, duration, font_option, font_size, y_pos):
|
| 45 |
"""Erstellt einen FFmpeg drawtext Filter, der ein Wort mit weichen Übergängen (Alpha-Kanal) einblendet."""
|
|
@@ -98,6 +115,7 @@ def generate_slideshow_with_audio(images, input_text, duration_per_word, duratio
|
|
| 98 |
font_option = f":fontfile='{font_path}'" if font_path else ""
|
| 99 |
|
| 100 |
# Audio verarbeiten
|
|
|
|
| 101 |
audio_temp_dir, temp_audio_file = save_temp_audio(audio_file) if audio_file else (None, None)
|
| 102 |
|
| 103 |
|
|
|
|
| 26 |
return font
|
| 27 |
return None # Fallback: FFmpeg soll selbst suchen (klappt manchmal nicht)
|
| 28 |
|
| 29 |
+
def save_temp_audio(audio_file_path):
|
| 30 |
+
"""
|
| 31 |
+
Speichert die hochgeladene Audio-Datei in einem temporären Verzeichnis.
|
| 32 |
+
Erwartet einen Dateipfad-String von Gradio.
|
| 33 |
+
"""
|
| 34 |
+
if not audio_file_path:
|
| 35 |
+
return None, None
|
| 36 |
+
|
| 37 |
+
# Gradio liefert einen String-Pfad zum temporären Speicherort
|
| 38 |
+
input_path = Path(audio_file_path)
|
| 39 |
+
|
| 40 |
+
# Bestimme die Erweiterung
|
| 41 |
+
ext = input_path.suffix
|
| 42 |
+
if ext.lower() not in allowed_audios:
|
| 43 |
+
ext = ".mp3"
|
| 44 |
+
|
| 45 |
+
# Erstelle das Zielverzeichnis und den Zielpfad
|
| 46 |
+
temp_audio_dir = Path(tempfile.mkdtemp())
|
| 47 |
+
temp_audio = temp_audio_dir / f"input{ext}"
|
| 48 |
+
|
| 49 |
+
# Kopiere die Datei vom Gradio-Temp-Pfad in unseren eigenen Temp-Pfad
|
| 50 |
+
try:
|
| 51 |
+
shutil.copyfile(input_path, temp_audio)
|
| 52 |
# Rückgabe des Verzeichnisses, das später gelöscht werden kann, und des Dateipfads
|
| 53 |
return temp_audio_dir, temp_audio
|
| 54 |
+
except Exception as e:
|
| 55 |
+
print(f"Fehler beim Kopieren der Audiodatei: {e}")
|
| 56 |
+
if temp_audio_dir.exists():
|
| 57 |
+
shutil.rmtree(temp_audio_dir)
|
| 58 |
+
return None, None
|
| 59 |
+
|
| 60 |
|
| 61 |
def create_timed_drawtext(word, start_time, duration, font_option, font_size, y_pos):
|
| 62 |
"""Erstellt einen FFmpeg drawtext Filter, der ein Wort mit weichen Übergängen (Alpha-Kanal) einblendet."""
|
|
|
|
| 115 |
font_option = f":fontfile='{font_path}'" if font_path else ""
|
| 116 |
|
| 117 |
# Audio verarbeiten
|
| 118 |
+
# audio_file ist der Pfad-String von Gradio
|
| 119 |
audio_temp_dir, temp_audio_file = save_temp_audio(audio_file) if audio_file else (None, None)
|
| 120 |
|
| 121 |
|