【发布时间】:2016-06-29 04:32:59
【问题描述】:
我已经找到了使用多个关键字激活 pocketsphinx 的方法,但我想根据所说的关键字运行不同的命令。当我说“Alexa”时,我已经让它连接到亚马逊的 Alexa 服务器,现在我想在我说“TV Off”和“TV On”时添加一个命令。
【问题讨论】:
标签: raspberry-pi cmusphinx pocketsphinx
我已经找到了使用多个关键字激活 pocketsphinx 的方法,但我想根据所说的关键字运行不同的命令。当我说“Alexa”时,我已经让它连接到亚马逊的 Alexa 服务器,现在我想在我说“TV Off”和“TV On”时添加一个命令。
【问题讨论】:
标签: raspberry-pi cmusphinx pocketsphinx
最好是用python,像这样:
import sys, os
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
import pyaudio
modeldir = "../../../model"
# Create a decoder with certain model
config = Decoder.default_config()
config.set_string('-hmm', os.path.join(modeldir, 'en-us/en-us'))
config.set_string('-dict', os.path.join(modeldir, 'en-us/cmudict-en-us.dict'))
config.set_string('-kws', 'keyword.list')
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
# Process audio chunk by chunk. On keyword detected perform action and restart search
decoder = Decoder(config)
decoder.start_utt()
while True:
buf = stream.read(1024)
if buf:
decoder.process_raw(buf, False, False)
else:
break
if decoder.hyp() == "tv on":
print ("Detected keyword tv on, turning on tv")
os.system('beep')
decoder.end_utt()
decoder.start_utt()
if decoder.hyp() == "tv off":
print ("Detected keyword tv off, turning off tv")
os.system('beep beep')
decoder.end_utt()
decoder.start_utt()
【讨论】: