You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Picovoice Porcupine自定义唤醒词失效:文件路径问题排查

问题:自定义Picovoice唤醒词加载失败报错

在Picovoice网站训练了自定义唤醒词并下载ZIP压缩包,解压后复制文件路径编写了如下代码:

import struct
import pyaudio
import pvporcupine
porcupine=None
paud=None
audio_stream=None
try:
    porcupine=pvporcupine.create(access_key="blahblah", keywords=["C:\\Users\\maste\\Downloads\\Jarvis_en_windows_v3_0_0.ppn"])
    paud=pyaudio.PyAudio()
    audio_stream=paud.open(rate=porcupine.sample_rate,channels=1,format=pyaudio.paInt16,input=True,frames_per_buffer=porcupine.frame_length)
    while True:
        keyword=audio_stream.read(porcupine.frame_length)
        keyword=struct.unpack_from("h"*porcupine.frame_length,keyword)
        keyword_index=porcupine.process(keyword)
        if keyword_index>=0:
            print("hotword detected")

finally:
    if porcupine is not None:
        porcupine.delete()
    if audio_stream is not None:
        audio_stream.close()
    if paud is not None:
        paud.terminate()

运行时出现如下错误:

ValueError: One or more keywords are not available by default. Available default keywords are:
jarvis, hey barista, bumblebee, americano, ok google, terminator, blueberry, hey siri, grasshopper, alexa, porcupine, hey google, computer, pico clock, picovoice, grapefruit

内置唤醒词可正常工作,怀疑是文件路径格式配置有误,请问问题出在哪里?


解决方案

问题核心是参数使用错误:

  • keywords 参数仅用于指定内置唤醒词的名称(比如"jarvis"),而自定义唤醒词的.ppn文件路径,需要通过keyword_paths参数传递。
  • 你把自定义唤醒词的文件路径放到了keywords参数中,程序会将其当作内置唤醒词名称去匹配,自然找不到对应项,因此抛出错误。

修复后的关键代码修改如下:

# 将原有的keywords参数替换为keyword_paths
porcupine=pvporcupine.create(access_key="blahblah", keyword_paths=["C:\\Users\\maste\\Downloads\\Jarvis_en_windows_v3_0_0.ppn"])

额外注意两点:

  • Windows路径可使用双反斜杠\\,或者在路径前加r使用原始字符串(如r"C:\Users\maste\Downloads\Jarvis_en_windows_v3_0_0.ppn"),避免转义字符引发的路径错误。
  • 需将代码中的"blahblah"替换为你自己的有效Picovoice Access Key,否则后续会出现权限相关报错。

内容的提问来源于stack exchange,提问作者symmetrical pattern with teal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 14:05:04