Skip to content

Commit

Permalink
file handling possible bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SevaSk committed Jun 2, 2023
1 parent 29389e9 commit 54f98f8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions AudioTranscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import wave
import os
import threading
from tempfile import NamedTemporaryFile
import tempfile
import custom_speech_recognition as sr
import io
from datetime import timedelta
Expand Down Expand Up @@ -48,16 +48,14 @@ def transcribe_audio_queue(self, audio_queue):

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)
Expand Down

0 comments on commit 54f98f8

Please sign in to comment.