如何在pocketsphinx上使用关键字列表

时间:2017-04-14 13:48:01

标签: python pocketsphinx

我正在使用pythonpocketsphinx构建一个程序,以便用我的声音来控制无人机。 我有这本词典:

DOWN  D AW N
GO  G OW
LEFT  L EH F T
RIGHT  R AY T
TURN  T ER N
UP  AH P

如果我说这个字典中的单词一切正常,但是如果我说一个单词不在字典中,pocketphinx将尝试从字典中找到最接近的匹配。例如,如果我说Stop pocketsphinx将显示UP,但如果是这种情况,我的程序应该什么都不做。 我在互联网上搜索,我发现这个问题可以通过使用关键字列表来解决,但我无法找到有关如何使用python的信息。 这是我到目前为止的代码

#!/usr/bin/env python

import os
from pocketsphinx import LiveSpeech, get_model_path

i = 0
j = 0
frase = ''
tab = [['x','o','o'],['o','o','o'],['o','o','o']]

def move():
    global i,j,frase

    if 'DOWN' in frase and i!= 2:
        i=i+1
    if 'UP' in frase and i!= 0:
        i=i-1
    if 'LEFT' in frase and j != 0:
        j = j - 1
    if 'RIGHT' in frase and j != 2:
        j = j + 1

def draw():
    global i,j
    s = 0
    for l in range(3):
        for c in range(3):
            if tab[l][c] == 'x':
                tab[l][c] = 'o'
                s = 1
                break
        if s == 1:
            break
    tab[i][j] = 'x'
    for p in tab:
        print p


model_path = get_model_path()

speech = LiveSpeech(
    verbose=False,
    sampling_rate=16000,
    buffer_size=2048,
    no_search=False,
    full_utt=False,
    hmm= os.path.join(model_path,'en-us'),
    lm=os.path.join(model_path, 'drone.lm.bin'),
    dic=os.path.join(model_path, 'drone.dict'),
)

for p in tab:
    print p

for phrase in speech:
    frase = str(phrase)
    print frase
    move()
    draw()

我正在使用带X的矩阵来模拟无人机。 我使用lmtool构建了字典和语言模型,提供了一个Corpus文件。

0 个答案:

没有答案