I am building a program with python
and pocketsphinx
in order to control a Drone with my voice.
I have this dictionary:
DOWN D AW N
GO G OW
LEFT L EH F T
RIGHT R AY T
TURN T ER N
UP AH P
If i say a word which is in this dictionary everything works fine, but if i say a word which is not in the dictionary pocketsphinx will try to find the closest match from the dictionary. E.g if i say Stop
pocketsphinx will display UP
, but if this is the case my program should do nothing.
I did search in the internet and i found that this problem can be solved by using a Keyword List, but i can't find information about how to use it with python.
This is the code i have so far
#!/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()
I am using a matrix with an X
just to simulate the drone.
I built the dictionary and the language model using lmtool
, provinding a Corpus file.