Spaces:
Running
Running
kevinwang676
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -217,28 +217,24 @@ def trim_audio(intervals, input_file_path, output_file_path):
|
|
217 |
# export the segment to a file
|
218 |
segment.export(output_file_path_i, format='wav')
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
def merge_audios(input_dir):
|
223 |
output_file = "AI配音版.wav"
|
224 |
-
#
|
225 |
-
files = [f for f in os.listdir(
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
# Initialize an empty audio segment
|
231 |
-
|
232 |
-
|
233 |
-
# Loop through
|
234 |
for file in sorted_files:
|
235 |
-
|
236 |
-
|
237 |
-
combined += audio
|
238 |
print(f"Merged: {file}")
|
239 |
-
|
240 |
-
# Export the
|
241 |
-
|
242 |
return "AI配音版.wav"
|
243 |
|
244 |
import shutil
|
|
|
217 |
# export the segment to a file
|
218 |
segment.export(output_file_path_i, format='wav')
|
219 |
|
220 |
+
def merge_audios(folder_path):
|
|
|
|
|
221 |
output_file = "AI配音版.wav"
|
222 |
+
# Get all WAV files in the folder
|
223 |
+
files = [f for f in os.listdir(folder_path) if f.endswith('.wav')]
|
224 |
+
# Sort files based on the last digit in their names
|
225 |
+
sorted_files = sorted(files, key=lambda x: int(x.split()[-1].split('.')[0][-1]))
|
226 |
+
|
|
|
227 |
# Initialize an empty audio segment
|
228 |
+
merged_audio = AudioSegment.empty()
|
229 |
+
|
230 |
+
# Loop through each file, in order, and concatenate them
|
231 |
for file in sorted_files:
|
232 |
+
audio = AudioSegment.from_wav(os.path.join(folder_path, file))
|
233 |
+
merged_audio += audio
|
|
|
234 |
print(f"Merged: {file}")
|
235 |
+
|
236 |
+
# Export the merged audio to a new file
|
237 |
+
merged_audio.export(output_file, format="wav")
|
238 |
return "AI配音版.wav"
|
239 |
|
240 |
import shutil
|