Spaces:
Sleeping
Sleeping
kevinwang676
commited on
Commit
•
61af3b3
1
Parent(s):
1b7bfce
Update app.py
Browse files
app.py
CHANGED
@@ -217,12 +217,22 @@ 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 |
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=
|
226 |
|
227 |
# Initialize an empty audio segment
|
228 |
merged_audio = AudioSegment.empty()
|
|
|
217 |
# export the segment to a file
|
218 |
segment.export(output_file_path_i, format='wav')
|
219 |
|
220 |
+
import re
|
221 |
+
|
222 |
+
def sort_key(file_name):
|
223 |
+
"""Extract the last number in the file name for sorting."""
|
224 |
+
numbers = re.findall(r'\d+', file_name)
|
225 |
+
if numbers:
|
226 |
+
return int(numbers[-1])
|
227 |
+
return -1 # In case there's no number, this ensures it goes to the start.
|
228 |
+
|
229 |
+
|
230 |
def merge_audios(folder_path):
|
231 |
output_file = "AI配音版.wav"
|
232 |
# Get all WAV files in the folder
|
233 |
files = [f for f in os.listdir(folder_path) if f.endswith('.wav')]
|
234 |
# Sort files based on the last digit in their names
|
235 |
+
sorted_files = sorted(files, key=sort_key)
|
236 |
|
237 |
# Initialize an empty audio segment
|
238 |
merged_audio = AudioSegment.empty()
|