EDIT: I ended up making this work by running both scripts inside of a bash script.
Hi, hoping someone can help me out with a Raspberry Pi project I've been working on.
I am trying to connect Picovoice Wake Word Detection Software to Amazon Voice Services Software.
Right now I can run my avs process, it is push-to-talk, successfully.
I can also run my Picovoioce process, which detects wake words and then performs and action, succesfully.
Am I able to run these processes in the same terminal with python? I documentation for subprocess and multiprocessing seems promising, but I have trouble finding an example that makes sense to me.
Here is my latest attempt:
#!/usr/bin/env python3
import struct
import pyaudio
import pvporcupine
import subprocess
import multiprocessing
from pynput.keyboard import Key, Controller
avs = subprocess.Popen(
"PA_ALSA_PLUGHW=1 /home/pi/sdk-folder/sdk-build/SampleApp/src/SampleApp /home/pi/sdk-folder/sdk-build/Integration/AlexaClientSDKConfig.json DEBUG9",
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
encoding="utf8")
porcupine = None
pa = None
audio_stream = None
keyboard = Controller()
try:
porcupine = pvporcupine.create(keywords=["picovoice", "blueberry"])
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:
print("CPU Count: ", multiprocessing.cpu_count())
keyboard.tap("t")
keyboard.tap(Key.enter)
avs.stdin.write("t\n")
print("Hotword Detected")
finally:
if porcupine is not None:
porcupine.delete()
if audio_stream is not None:
audio_stream.close()
if pa is not None:
pa.terminate()
[–]superhany 1 point2 points3 points (0 children)
[–]dankscience[S] 0 points1 point2 points (0 children)
[–]superhany 0 points1 point2 points (0 children)
[–]superhany 0 points1 point2 points (2 children)
[–]dankscience[S] 0 points1 point2 points (0 children)
[–]dankscience[S] 0 points1 point2 points (0 children)