fixed files opening and closing improperly

This commit is contained in:
SevaSk 2023-05-31 17:30:17 -04:00
parent 46d37a3df9
commit 6a20d04080
2 changed files with 4 additions and 4 deletions

View File

@ -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':

View File

@ -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()