I have 2 functions
def record_save():
r = sr.Recognizer()
with sr.Microphone(device_index=0) as source:
r.adjust_for_ambient_noise(source)
print("Say something ")
audio = r.listen(source)
print("Done ")
with open("audio.wav", "wb") as f:
f.write(audio.get_wav_data())
try:
text = r.recognize_google(audio)
print("You said :", text)
except Exception as error:
print("Could not recognize what you said")
print(error)
pass
This function is to get the audio from the mic and store it in a .wav
file. It also stores the audio transcription in a variable text
def listen_to_speaker():
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'avc1')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480))
while cap.isOpened():
ret, frame = cap.read()
if ret:
frame = cv2.resize(frame, (640, 480))
out.write(frame)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
pass
This uses OpenCV
to record and store a video in a .avi
file.
I used multiprocessing in order to run the two processes simultaneously, like so:
t1 = Process(target=listen_to_speaker)
t1.start()
t2 = Process(target=record_save)
t2.start()
I get the following error message:
objc[6742]: +[AVCaptureDevice initialize] may have been in progress in another thread when fork() was called.
We cannot safely call it or ignore it in the fork() child process.
Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
I want to be able to run these 2 functions simultaneously in order to record an audio and video that correspond to each other. Currently, first the audio is recorded and saved, and then the webcam turns on to record the video.
I have also tried adding
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
to the end of the file after running nano .bash_profile
, but I get the same error
I tried OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES python3 my-program.py
as well, but to no avail