I am using the pvporcupine library to detect the keyword “Hey Sasha” through the microphone in Python. After executing the code, the message “Listening for keyword…” appears in the console, but nothing happens when I say the keyword.How to solve this problem?
Thanks!
def detect_wake_word(keyword_path):
handle = pvporcupine.create(
access_key="access_key", keyword_paths=[keyword_path], sensitivities=[0.5]
)
try:
print(f'Listening for keyword...')
while True:
pcm = sd.rec(
int(handle.frame_length), samplerate=handle.sample_rate, channels=1, dtype='int16'
)
sd.wait()
pcm = pcm.flatten()
result = handle.process(pcm)
if result >= 0:
print(f'Detected keyword')
except KeyboardInterrupt:
print("Detection stopped by user.")
finally:
if handle is not None:
handle.delete()
if __name__ == "__main__":
keyword_path = "wake_word.ppn"
detect_wake_word(keyword_path)
At the beginning, I thought that the problem could be in the sounddevice library, so I changed it to PyAudio, but nothing happened. Then, I tried to change the parameters of the “handle,” but the result remained the same.
Kibar Jafarguliyev is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.