kevinwang676 commited on
Commit
08f2e08
·
verified ·
1 Parent(s): a7c051e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -129,12 +129,19 @@ def trim_audio(intervals, input_file_path, output_file_path):
129
  for i, (start_time, end_time) in enumerate(intervals):
130
  # extract the segment of the audio
131
  segment = audio[start_time*1000:end_time*1000]
132
-
133
- # construct the output file path
134
  output_file_path_i = f"{output_file_path}_{i}.wav"
135
-
136
- # export the segment to a file
137
- segment.export(output_file_path_i, format='wav')
 
 
 
 
 
 
 
 
 
138
 
139
  import re
140
 
 
129
  for i, (start_time, end_time) in enumerate(intervals):
130
  # extract the segment of the audio
131
  segment = audio[start_time*1000:end_time*1000]
 
 
132
  output_file_path_i = f"{output_file_path}_{i}.wav"
133
+
134
+ if len(segment) < 3000:
135
+ # Calculate how many times to repeat the audio to make it at least 2 seconds long
136
+ repeat_count = (3000 // len(segment)) + 2
137
+ # Repeat the audio
138
+ longer_audio = segment * repeat_count
139
+ # Save the extended audio
140
+ print(f"Audio was less than 3 seconds. Extended to {len(longer_audio)} milliseconds.")
141
+ longer_audio.export(output_file_path_i, format='wav')
142
+ else:
143
+ print("Audio is already 3 seconds or longer.")
144
+ segment.export(output_file_path_i, format='wav')
145
 
146
  import re
147