2016-02-28 37 views
1

我一直在试图制作一个使用sl4a.Android.recognizeSpeech函数的qpython程序。该功能在网上很好地工作。qpython3中的脱机语音识别

在我的手机设置中,我打开并下载了离线语音识别功能,谷歌现在可以很好地离线使用,但python语音根本不起作用,请我每次尝试一次。

示例代码:

import sl4a 
import time 

droid = sl4a.Android() 

def speak(text): 
    droid.ttsSpeak(text) 
    while droid.ttsIsSpeaking()[1] == True: 
     time.sleep(1) 

def listen(): 
    return droid.recognizeSpeech('Speak Now',None,None) 

def login(): 
    speak('Passphrase, please') 
    try: 
     phrase = listen().result.lower() 
    except: 
     phrase = droid.dialogGetPassword('Passphrase').result 
    print(phrase) 
    if phrase == 'pork chops': 
     speak('Welcome') 
    else: 
     speak('Access Denied') 
     exit(0) 

login() 

回答

1
droid.recognizeSpeech("foo", None, None) 

返回与索引号识别的语音1.所以,如果你要访问它,你有一个数组键入

return droid.recognizeSpeech("foo", None, None)[1] 
+0

感谢回答。 – Ryzokuken