Luigi commited on
Commit
0ae11fc
·
1 Parent(s): c680485

improve exception handling on sensevoice branch

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -279,6 +279,7 @@ def _transcribe_sense_gpu_stream(model_id: str, language: str, audio_path: str,
279
  diary = diarizer({"waveform": waveform, "sample_rate": sample_rate}, hook=hook)
280
  snippets = []
281
  cache = {}
 
282
  for turn, _, speaker in diary.itertracks(yield_label=True):
283
  start_ms, end_ms = int(turn.start*1000), int(turn.end*1000)
284
  segment = AudioSegment.from_file(audio_path)[start_ms:end_ms]
@@ -290,11 +291,12 @@ def _transcribe_sense_gpu_stream(model_id: str, language: str, audio_path: str,
290
  except Exception as e:
291
  cprint(f'Error: {e}','red')
292
  os.unlink(tmp.name)
293
- txt = rich_transcription_postprocess(segs[0]['text'])
294
- if not enable_punct:
295
- txt = re.sub(r"[^\w\s]", "", txt)
296
- txt = converter.convert(txt)
297
- snippets.append(f"[{speaker}] {txt}")
 
298
  yield "", format_diarization_html(snippets)
299
  return
300
 
 
279
  diary = diarizer({"waveform": waveform, "sample_rate": sample_rate}, hook=hook)
280
  snippets = []
281
  cache = {}
282
+ segs = None
283
  for turn, _, speaker in diary.itertracks(yield_label=True):
284
  start_ms, end_ms = int(turn.start*1000), int(turn.end*1000)
285
  segment = AudioSegment.from_file(audio_path)[start_ms:end_ms]
 
291
  except Exception as e:
292
  cprint(f'Error: {e}','red')
293
  os.unlink(tmp.name)
294
+ if segs:
295
+ txt = rich_transcription_postprocess(segs[0]['text'])
296
+ if not enable_punct:
297
+ txt = re.sub(r"[^\w\s]", "", txt)
298
+ txt = converter.convert(txt)
299
+ snippets.append(f"[{speaker}] {txt}")
300
  yield "", format_diarization_html(snippets)
301
  return
302