kevinwang676 commited on
Commit
5f2b417
·
verified ·
1 Parent(s): ddfedca

Update app_srt.py

Browse files
Files changed (1) hide show
  1. app_srt.py +12 -1
app_srt.py CHANGED
@@ -515,12 +515,23 @@ def trim_audio(intervals, input_file_path, output_file_path):
515
  # export the segment to a file
516
  segment.export(output_file_path_i, format='wav')
517
 
 
 
 
 
 
 
 
 
 
 
 
518
  def merge_audios(folder_path):
519
  output_file = "AI配音版.wav"
520
  # Get all WAV files in the folder
521
  files = [f for f in os.listdir(folder_path) if f.endswith('.wav')]
522
  # Sort files based on the last digit in their names
523
- sorted_files = sorted(files, key=lambda x: int(x.split()[-1].split('.')[0][-1]))
524
 
525
  # Initialize an empty audio segment
526
  merged_audio = AudioSegment.empty()
 
515
  # export the segment to a file
516
  segment.export(output_file_path_i, format='wav')
517
 
518
+
519
+ import re
520
+
521
+ def sort_key(file_name):
522
+ """Extract the last number in the file name for sorting."""
523
+ numbers = re.findall(r'\d+', file_name)
524
+ if numbers:
525
+ return int(numbers[-1])
526
+ return -1 # In case there's no number, this ensures it goes to the start.
527
+
528
+
529
  def merge_audios(folder_path):
530
  output_file = "AI配音版.wav"
531
  # Get all WAV files in the folder
532
  files = [f for f in os.listdir(folder_path) if f.endswith('.wav')]
533
  # Sort files based on the last digit in their names
534
+ sorted_files = sorted(files, key=sort_key)
535
 
536
  # Initialize an empty audio segment
537
  merged_audio = AudioSegment.empty()