terry-li-hm commited on
Commit
c15cb6e
·
1 Parent(s): b30221e

Update sv.py

Browse files
Files changed (1) hide show
  1. sv.py +7 -7
sv.py CHANGED
@@ -185,16 +185,16 @@ def parse_time(time_str):
185
  return int(h) * 3600 + int(m) * 60 + float(s)
186
 
187
 
188
- def format_time(seconds, use_short_format=True):
189
  if isinstance(seconds, datetime.timedelta):
190
  seconds = seconds.total_seconds()
191
 
192
  minutes, seconds = divmod(seconds, 60)
193
  hours, minutes = divmod(int(minutes), 60)
194
 
195
- if use_short_format or (hours == 0 and minutes == 0):
196
- return f"{seconds:05.3f}s"
197
- elif hours == 0:
198
  return f"{minutes:02d}:{seconds:06.3f}"
199
  else:
200
  return f"{hours:02d}:{minutes:02d}:{seconds:06.3f}"
@@ -348,9 +348,9 @@ def process_audio(audio_path, language="yue", fs=16000):
348
  # Format the results
349
  formatted_text = ""
350
  for speaker, start, end, duration, text in results:
351
- start_str = format_time_with_leading_zeros(start)
352
- end_str = format_time_with_leading_zeros(end)
353
- duration_str = format_time_with_leading_zeros(duration)
354
  speaker_num = "1" if speaker == "SPEAKER_00" else "2"
355
  line = f"{start_str} - {end_str} ({duration_str}) Speaker {speaker_num}: {text}"
356
  formatted_text += line + "\n"
 
185
  return int(h) * 3600 + int(m) * 60 + float(s)
186
 
187
 
188
+ def format_time(seconds, use_short_format=True, always_use_seconds=False):
189
  if isinstance(seconds, datetime.timedelta):
190
  seconds = seconds.total_seconds()
191
 
192
  minutes, seconds = divmod(seconds, 60)
193
  hours, minutes = divmod(int(minutes), 60)
194
 
195
+ if always_use_seconds or (use_short_format and hours == 0 and minutes == 0):
196
+ return f"{seconds:06.3f}s"
197
+ elif use_short_format or hours == 0:
198
  return f"{minutes:02d}:{seconds:06.3f}"
199
  else:
200
  return f"{hours:02d}:{minutes:02d}:{seconds:06.3f}"
 
348
  # Format the results
349
  formatted_text = ""
350
  for speaker, start, end, duration, text in results:
351
+ start_str = format_time(start, always_use_seconds=True)
352
+ end_str = format_time(end, always_use_seconds=True)
353
+ duration_str = format_time(duration, always_use_seconds=True)
354
  speaker_num = "1" if speaker == "SPEAKER_00" else "2"
355
  line = f"{start_str} - {end_str} ({duration_str}) Speaker {speaker_num}: {text}"
356
  formatted_text += line + "\n"