qpython3中的离线语音识别 [英] Offline Speech Recognition in qpython3

查看:700
本文介绍了qpython3中的离线语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been trying to make a qpython program that uses sl4a.Android.recognizeSpeech function. The functionality works fine online.

在我的手机设置中,我打开并下载了离线语音识别功能,而Google现在可以在离线状态下正常运行,但是python语音功能根本无法正常工作,要求我每次重试一次.

In my phone settings, I turned on and downloaded offline speech recognition and google now works fine offline, but the python speech does not work at all, asking me to try again every single time.

示例代码:

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()

推荐答案

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

返回索引编号为1的具有识别语音的数组.因此,如果要访问它,则必须输入

returns an Array with the recognized Speech in Index number 1. So if you want to access it, you have to type

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

这篇关于qpython3中的离线语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆