cnph001 commited on
Commit
18e62e9
·
verified ·
1 Parent(s): 2136be9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -16
app.py CHANGED
@@ -202,6 +202,8 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch):
202
  timed_audio_segments = []
203
  max_end_time_ms = 0
204
  previous_end_time_ms = 0
 
 
205
 
206
  for i, line in enumerate(lines):
207
  start_time, audio_paths = await process_transcript_line(line, voice, rate, pitch)
@@ -220,24 +222,13 @@ async def transcript_to_speech(transcript_text, voice, rate, pitch):
220
  intended_start_time = start_time
221
 
222
  if i > 0:
223
- prev_line_match = re.match(r'(\d{2}):(\d{2}):(\d{2}),(\d{3})\s+.*', lines[i-1])
224
- if prev_line_match:
225
- prev_h, prev_m, prev_s, prev_ms = prev_line_match.groups()
226
- previous_start_time_ms = (
227
- int(prev_h) * 3600000 +
228
- int(prev_m) * 60000 +
229
- int(prev_s) * 1000 +
230
- int(prev_ms)
231
- )
232
- time_difference = start_time - previous_start_time_ms
233
- # print(f"current_audio_duration:{current_audio_duration}, time_difference:{time_difference}, previous_end_time_ms:{previous_end_time_ms}, start_time:{start_time}")
234
- if current_audio_duration > time_difference:
235
- intended_start_time = previous_end_time_ms
236
- # print(f"intended_start_time:{intended_start_time}")
237
- else:
238
- intended_start_time = start_time
239
 
240
  timed_audio_segments.append({'start': intended_start_time, 'audio': combined_line_audio})
 
241
  previous_end_time_ms = max(previous_end_time_ms, intended_start_time + current_audio_duration)
242
  max_end_time_ms = max(max_end_time_ms, previous_end_time_ms)
243
  elif audio_paths:
 
202
  timed_audio_segments = []
203
  max_end_time_ms = 0
204
  previous_end_time_ms = 0
205
+ previous_start_time_ms = 0 # Keep track of the *start* time of the previous segment
206
+
207
 
208
  for i, line in enumerate(lines):
209
  start_time, audio_paths = await process_transcript_line(line, voice, rate, pitch)
 
222
  intended_start_time = start_time
223
 
224
  if i > 0:
225
+ time_difference = start_time - previous_start_time_ms
226
+
227
+ if current_audio_duration > time_difference:
228
+ intended_start_time = previous_end_time_ms
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
  timed_audio_segments.append({'start': intended_start_time, 'audio': combined_line_audio})
231
+ previous_start_time_ms = start_time #update previous start time
232
  previous_end_time_ms = max(previous_end_time_ms, intended_start_time + current_audio_duration)
233
  max_end_time_ms = max(max_end_time_ms, previous_end_time_ms)
234
  elif audio_paths: