From 54f98f8280567b6be62324e9f69a5cff73a7780a Mon Sep 17 00:00:00 2001 From: SevaSk Date: Fri, 2 Jun 2023 11:48:30 -0400 Subject: [PATCH] file handling possible bug fix --- AudioTranscriber.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/AudioTranscriber.py b/AudioTranscriber.py index 6be40b8..b37eae8 100644 --- a/AudioTranscriber.py +++ b/AudioTranscriber.py @@ -3,7 +3,7 @@ import torch import wave import os import threading -from tempfile import NamedTemporaryFile +import tempfile import custom_speech_recognition as sr import io from datetime import timedelta @@ -48,16 +48,14 @@ class AudioTranscriber: text = '' try: - temp_file = NamedTemporaryFile(delete=False, suffix=".wav") + fd, path = tempfile.mkstemp(suffix=".wav") + os.close(fd) + source_info["process_data_func"](source_info["last_sample"], path) + text = self.audio_model.get_transcription(path) except Exception as e: print(e) - - temp_file.close() - - source_info["process_data_func"](source_info["last_sample"], temp_file.name) - text = self.audio_model.get_transcription(temp_file.name) - - os.unlink(temp_file.name) + finally: + os.unlink(path) if text != '' and text.lower() != 'you': self.update_transcript(who_spoke, text, time_spoken)