kevinwang676 commited on
Commit
e91b6ce
1 Parent(s): 37981bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -227,12 +227,21 @@ def trim_audio(intervals, input_file_path, output_file_path):
227
  for i, (start_time, end_time) in enumerate(intervals):
228
  # extract the segment of the audio
229
  segment = audio[start_time*1000:end_time*1000]
230
-
231
- # construct the output file path
232
  output_file_path_i = f"{output_file_path}_{i}.wav"
 
 
 
 
 
 
 
 
 
 
 
 
233
 
234
- # export the segment to a file
235
- segment.export(output_file_path_i, format='wav')
236
 
237
  import re
238
 
 
227
  for i, (start_time, end_time) in enumerate(intervals):
228
  # extract the segment of the audio
229
  segment = audio[start_time*1000:end_time*1000]
 
 
230
  output_file_path_i = f"{output_file_path}_{i}.wav"
231
+
232
+ if len(segment) < 3000:
233
+ # Calculate how many times to repeat the audio to make it at least 2 seconds long
234
+ repeat_count = (3000 // len(segment)) + 2
235
+ # Repeat the audio
236
+ longer_audio = segment * repeat_count
237
+ # Save the extended audio
238
+ print(f"Audio was less than 3 seconds. Extended to {len(longer_audio)} milliseconds.")
239
+ longer_audio.export(output_file_path_i, format='wav')
240
+ else:
241
+ print("Audio is already 3 seconds or longer.")
242
+ segment.export(output_file_path_i, format='wav')
243
 
244
+
 
245
 
246
  import re
247