qpython3中的离线语音识别

2024-10-06 11:22:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试制作一个使用sl4a.Android.recognizeSpeech函数的qpython程序。该功能在网上运行良好。在

在我的手机设置中,我打开并下载了离线语音识别功能,谷歌现在离线工作正常,但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()

Tags: textimport功能nonetimedef语音listen
2条回答
droid.recognizeSpeech("foo", None, None)

返回索引号为1的已识别语音的数组。所以如果你想访问它,你必须输入

^{pr2}$

实际上,以上这些对我来说都不管用。所以我就这样解决了:

x, result, error = droid.recognizeSpeech("Speak")

result变量存储从用户识别的语音

示例:

^{pr2}$

相关问题 更多 >