在 PocketSphinx 中使用不同的单词运行不同的命令 [英] Running different commands with different words in PocketSphinx

查看:56
本文介绍了在 PocketSphinx 中使用不同的单词运行不同的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了使用多个关键字激活 Pocketsphinx 的方法,但我想根据所说的关键字运行不同的命令.当我说Alexa"时,我已经让它连接到亚马逊的 Alexa 服务器,现在我想在我说TV Off"和TV On"时添加一个命令.

I have found ways to make pocketsphinx activate using multiple keywords, but I want to run diffrent commands depending on which keyword was said. I have already made it connect to Amazon's Alexa server when "Alexa" is said and now I want to add a command when I say "TV Off" and "TV On."

推荐答案

最好使用 python,类似这样:

The best thing is to use python, something like this:

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 中使用不同的单词运行不同的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆