Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
|
3 |
import glob
|
4 |
import os
|
|
|
|
|
5 |
from pydub import AudioSegment
|
6 |
|
7 |
def process_audio(input_file):
|
@@ -46,24 +48,38 @@ def find_audio_chunks():
|
|
46 |
return wav_files # Returning the list of file paths
|
47 |
|
48 |
def concatenate_audio(output_filename="final_output.wav"):
|
49 |
-
"""Concatenates all audio chunks and saves them to a final output file."""
|
|
|
50 |
wav_files = find_audio_chunks() # Get sorted audio file paths
|
51 |
|
52 |
if not wav_files:
|
53 |
print("No audio files found.")
|
54 |
return []
|
55 |
|
|
|
|
|
|
|
56 |
# Load and concatenate all audio files
|
57 |
combined = AudioSegment.empty()
|
|
|
|
|
58 |
for file in wav_files:
|
59 |
audio = AudioSegment.from_wav(file)
|
60 |
combined += audio
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
# Export the final combined audio
|
63 |
-
combined.export(
|
64 |
-
print(f"Concatenated audio saved
|
65 |
|
66 |
-
return
|
67 |
|
68 |
|
69 |
def infer(audio_input_path):
|
|
|
2 |
|
3 |
import glob
|
4 |
import os
|
5 |
+
import shutil
|
6 |
+
import tempfile
|
7 |
from pydub import AudioSegment
|
8 |
|
9 |
def process_audio(input_file):
|
|
|
48 |
return wav_files # Returning the list of file paths
|
49 |
|
50 |
def concatenate_audio(output_filename="final_output.wav"):
|
51 |
+
"""Concatenates all audio chunks and saves them to a final output file in a temporary directory."""
|
52 |
+
|
53 |
wav_files = find_audio_chunks() # Get sorted audio file paths
|
54 |
|
55 |
if not wav_files:
|
56 |
print("No audio files found.")
|
57 |
return []
|
58 |
|
59 |
+
# Create a temporary directory
|
60 |
+
temp_dir = tempfile.mkdtemp()
|
61 |
+
|
62 |
# Load and concatenate all audio files
|
63 |
combined = AudioSegment.empty()
|
64 |
+
temp_wav_files = []
|
65 |
+
|
66 |
for file in wav_files:
|
67 |
audio = AudioSegment.from_wav(file)
|
68 |
combined += audio
|
69 |
+
|
70 |
+
# Move individual files to the temp directory
|
71 |
+
temp_file_path = os.path.join(temp_dir, os.path.basename(file))
|
72 |
+
shutil.move(file, temp_file_path)
|
73 |
+
temp_wav_files.append(temp_file_path)
|
74 |
+
|
75 |
+
# Define the final output path in the temporary directory
|
76 |
+
temp_output_path = os.path.join(temp_dir, output_filename)
|
77 |
+
|
78 |
# Export the final combined audio
|
79 |
+
combined.export(temp_output_path, format="wav")
|
80 |
+
print(f"Concatenated audio saved at {temp_output_path}")
|
81 |
|
82 |
+
return temp_output_path, temp_wav_files # Returning temp paths
|
83 |
|
84 |
|
85 |
def infer(audio_input_path):
|