Python语音识别-Sphinx

时间:2020-09-23 00:39:14

标签: python performance speech-recognition pocketsphinx

我正在制作一个简单的语音识别程序,它将使我能够通过语音命令控制机器人。我只希望程序查找某些单词并且相对较快。我的项目基于米歇尔·里夫斯(Micheal Reeves)的想法,“我制造了一个可以在眼睛上照射激光的机器人”,并试图创建类似于他的视频中所见语音命令的东西。

我遇到的问题是狮身人面像速度很快,但是(编辑:不准确)。除此之外,当我启用关键字时,结果变得很奇怪。如果我说命令关闭,输出将是:

"three  nine  one  four  five  eight  two  one  eight  nine  three  four  two  six  zero  eight  nine  two  one  six  four  eight  seven  one  three  four  nine  five  eight  two  eight 
four  five  nine  three  one  two  eight  six  nine  three  five  seven  two  zero  one  nine  five  eight  two  four  four  nine  one  five  eight  three  two  six  four  two  zero  seven  one  nine  three  four  five  eight  two  five  one  three  four  eight  two  six  eight  zero  one  three  four  five  two  seven  eight  eight  three  nine  five  two  four  eight  one  two  eight  two  eight  two  eight  command shutdown  command  eight  one  four  three  eight  two  two  eight "

我不确定要解决此问题,我尝试做recognise_google,但是它更准确,但确实很慢,我希望启用关键字,以便它仅检查a是否表示单词集合,然后将其打印出来。屏幕,如果我这样做。

我遇到的另一个问题是listen_in_background()函数。我似乎无法正常工作。

这是我的代码:

import speech_recognition as sr
import pocketsphinx

keywords = [
    ("command", 1), 
    ("one", 0), 
    ("two", 0), 
    ("three", 0), 
    ("four", 0), 
    ("five", 0), 
    ("six", 0), 
    ("seven", 0), 
    ("eight", 0), 
    ("nine", 0), 
    ("zero", 0), 
    ("command x axis add", 0), 
    ("command y axis add", 0), 
    ("command x axis subtract", 0), 
    ("command y axis subtract", 0), 
    ("command clear shift string", 0), 
    ("command shutdown", 0),
    ("command flip tracking", 0), 
    ("command pause", 0), 
    ("command detect face", 0), 
    ("command detect body", 0)
]

def speech2text():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        audio = r.listen(source) #this is were i want to listen in the background to run it at the same 
        #time as other code
    try:
        data = r.recognize_sphinx(audio, keyword_entries = keywords)
        return data
    except:
        return "Error..."

while True:
    print(speech2text())

0 个答案:

没有答案