Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shutil.rmtree(tmp_dir, ignore_errors = True)
return False
try:
request_srt_content = json.loads('{"srt":"' + stt_task.request_srt_content + '"}')['srt']
except:
stt_task.add_step(TaskStep(comment = 'SRT cannot be parsed'))
shutil.rmtree(tmp_dir, ignore_errors = True)
return False
## Conduct STT
# convert SRT to list of Subtitle
subtitle = list(parse(request_srt_content))
# segment audio into smaller chunks
flac_path_list = generate_audio_segments(media_file_path, subtitle, elastic = 0.5)
stt_task.add_step(TaskStep(comment = 'File segmented'))
lang = 'en'
if stt_task.lang:
lang = stt_task.lang
# Call API
logging.warning(flac_path_list)
result_recognize = recognize_segments(flac_path_list, lang_code = lang)
logging.warning(result_recognize)
new_subtitle = merge_result(subtitle, result_recognize)
stt_task.add_step(TaskStep(comment = 'STT conducted'))
# Clean up and put back punctuations
if lang == 'en' and stt_task.correct:
new_subtitle = segment_subtitle(new_subtitle)