豪猪中的唤醒词检测

问题描述 投票:0回答:1

我正在尝试在Python中实现豪猪唤醒词,并按照here

的说明进行操作

我有以下代码:

import pvporcupine

### Porcupine wakeword
handle = pvporcupine.create(keywords=['computer', 'jarvis'])

def get_next_audio_frame():
    pass

while True:
    keyword_index = handle.process(get_next_audio_frame())
    if keyword_index >= 0:
        # Insert detection event callback here
        print('Yes sir?')
        pass

但我收到以下错误:

❯ python3 porcupine.py Traceback (most recent call last):   File "porcupine.py", line 10, in <module>
    keyword_index = handle.process(get_next_audio_frame())   File "/home/rupstar/Computer/lib/python3.8/site-packages/pvporcupine/porcupine.py", line 129, in process
    if len(pcm) != self.frame_length: TypeError: object of type 'NoneType' has no len()
python python-3.x ubuntu-20.04
1个回答
4
投票

这可能并不完美(事实并非如此),但它展示了我如何在 Windows 10 计算机上运行 Ubuntu 20.04 的 WSL2 上使用 Python 创建个人语音助手。语音助手响应唤醒词(Jarvis 或计算机),然后执行命令。 与这篇文章相关的是如何调用豪猪:

#!/usr/bin/env python3
#Porcupine wakeword includes
import struct
import pyaudio
import pvporcupine

porcupine = None
pa = None
audio_stream = None

try:
    porcupine = pvporcupine.create(keywords=["computer", "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:
            print("Hotword Detected")
            speak("Computer online")
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.