I have a script that is listening to an mp3 stream. When I detect someone talking, I record the audio to a wav file then create a thread to transcribe the recorded audio and save to a db (So the listening part of the script can continue). calling model.transcribe in this thread seems to just halt forever. But When I ctrl+c my program it prints out the transcript and performs the rest of the threaded function saving it to the db.
frames = deque()
lock = threading.lock()
exit_event = threading.event()
def save_to_db(audio_path):
msg_text = model.transcribe(audio_path)["text"]
print(msg_text)
# CODE TO SAVE TO DB
def listen_audio():
while True:
if exit_event.is_set():
break
data = b""
for _ in range(3):
t, _ = sock.recvfrom(1024)
data += t
lock.acquire()
frames.append(data)
lock.release()
def record_audio():
while True:
if exit_event.is_set():
break
lock.acquire()
if len(frames) > 30:
# get the first 5 frames
data = b"".join(frames)
frames.clear()
lock.release()
else:
lock.release()
continue
# PROCESS AUDIO TO FIND volume
if volume > THRESHOLD:
# recordmaudio and save to file
new_thread = threading.Thread(target=save_to_db, args=(filepath,))
new_thread.start()
#SETUP FOR SOCKET CONNECTION
write_thread = threading.Thread(target=listen_audio)
write_thread.start()
read_thread = threading.Thread(target=record_audio)
read_thread.start()```
I have just put together a rough overview of what im doing and this code won't run