I'm trying to have the online message print before I speak I'm not sure why it doesn't. I can show the full code if its needed but thats the specific part.
def main():
print("Online")
porcupine = None
pa = None
audio_stream = None
try:
porcupine = pvporcupine.create(keywords=["jarvis"])
pa = pyaudio.PyAudio()
audio_stream = pa.open(
rate=porcupine.sample_rate,
channels=1,
format=pyaudio.paInt16,
input=True,
frames_per_buffer=porcupine.frame_length)
while True:
pcm = audio_stream.read(porcupine.frame_length)
pcm = struct.unpack_from("h" * porcupine.frame_length, pcm)
keyword_index = porcupine.process(pcm)
if keyword_index >= 0:
action()
time.sleep(1)
print("Listening...")
finally:
if porcupine is not None:
porcupine.delete()
if audio_stream is not None:
audio_stream.close()
if pa is not None:
pa.terminate()
main()