运行 PocketSphinx 中不同的命令用不同的词
Running different commands with different words in PocketSphinx
我找到了使用多个关键字激活 pocketsphinx 的方法,但我想 运行 根据说的关键字使用不同的命令。我已经在说 "Alexa" 时连接到亚马逊的 Alexa 服务器,现在我想在说 "TV Off" 和 "TV On."
时添加命令
最好的办法是使用 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()
我找到了使用多个关键字激活 pocketsphinx 的方法,但我想 运行 根据说的关键字使用不同的命令。我已经在说 "Alexa" 时连接到亚马逊的 Alexa 服务器,现在我想在说 "TV Off" 和 "TV On."
时添加命令最好的办法是使用 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()