porcupine语音唤醒python实现

note

it is not for arm
pyaudio <= 3.6 version
porcupine 3.5 3.6 not 3.7

code

import struct
import pyaudio
import pvporcupine

#porcupine = pvporcupine.create(keywords=['porcupine', 'ok google', "picovoice", "blueberry"])
porcupine = pvporcupine.create(keyword_paths=['samel__en_windows_2021-10-26-utc_v1_9_0.ppn'])

pa = pyaudio.PyAudio()

audio_stream = pa.open(
                    rate=porcupine.sample_rate,
                    channels=1,
                    format=pyaudio.paInt16,
                    input=True,
                    frames_per_buffer=porcupine.frame_length)

#def get_next_audio_frame():
#  return 


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:
        # Insert detection event callback here
        print("sdfsa")

application

reference

https://github.com/Picovoice/porcupine/issues/255
https://www.jianshu.com/p/cadb9d80f180

原文地址:https://www.cnblogs.com/fengmao31/p/15380116.html