From 6a20d04080d46841665caa8b7868323d77134eb7 Mon Sep 17 00:00:00 2001 From: SevaSk Date: Wed, 31 May 2023 17:30:17 -0400 Subject: [PATCH] fixed files opening and closing improperly --- AudioTranscriber.py | 3 ++- TranscriberModels.py | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AudioTranscriber.py b/AudioTranscriber.py index a29dc69..0002d20 100644 --- a/AudioTranscriber.py +++ b/AudioTranscriber.py @@ -48,10 +48,11 @@ class AudioTranscriber: text = '' temp_file = NamedTemporaryFile(delete=False, suffix=".wav") + temp_file.close() + source_info["process_data_func"](source_info["last_sample"], temp_file.name) text = self.audio_model.get_transcription(temp_file.name) - temp_file.close() os.unlink(temp_file.name) if text != '' and text.lower() != 'you': diff --git a/TranscriberModels.py b/TranscriberModels.py index 60a3dd8..b0dc87e 100644 --- a/TranscriberModels.py +++ b/TranscriberModels.py @@ -24,11 +24,10 @@ class WhisperTranscriber: class APIWhisperTranscriber: def get_transcription(self, wav_file_path): - audio_file= open(wav_file_path, "rb") try: - result = openai.Audio.translate("whisper-1", audio_file) + with open(wav_file_path, "rb") as audio_file: + result = openai.Audio.translate("whisper-1", audio_file) except Exception as e: print(e) return '' - return result['text'].strip() \ No newline at end of file