首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TypeError:“int”类型的参数在不正确的语音识别时不可迭代

TypeError:“int”类型的参数在不正确的语音识别时不可迭代
EN

Stack Overflow用户
提问于 2022-04-17 05:12:35
回答 1查看 46关注 0票数 0

我正在为一个学校项目开发一个TTS/STT系统,它一直进行得很好,直到当代码经过"Google语音识别不承认您所说的话“时,我才开始得到这个特定的错误。我不知道为什么我会犯这个错误。我正在使用的python库只是python、语音识别和py音频库。我的密码在下面。

代码语言:javascript
复制
from subprocess import call
import speech_recognition as sr
import serial
r = sr.Recognizer()
import os,time
def listen1():
    with sr.Microphone(device_index = 2) as source:
            r.adjust_for_ambient_noise(source)
            print("Please speak.");
            audio = r.listen(source)
            print("Heard.");
    return audio
def voice(audio1):
    try:
        text1 = r.recognize_google(audio1)
        ##call('espeak ' +text, shell=True)
        print("You said: " +text1);
        return text1;
    except sr.UnknownValueError:
        call(["espeak", "-a 200 -v en+1 ", "Google Speech Recognition did not recognize what you said."])
        print("Google Speech Recognition did not recognize what you said.")
        return 0
    except sr.RequestError as e:
        print("Could not request results fromm Google")
        return 0
def main(text):
    audio1 = listen1()
    text = voice(audio1)  
    if 'hello' in text:
        call(["espeak", "-a 200 -v en+1" , "Hi, how are you"])
    if 'good' in text:
        call(["espeak", "-a 200 -v en+1" , "Good to hear, now what will you have me do?"])
    if 'exit' in text:
        call(["espeak", "-a 200 -v en+1" , "Thank you, exiting."])
        exit()
    text = {}
    main(text)
if __name__ =='__main__':
 while(1):
    audio1=listen1()
    text = voice(audio1)
    if text == 'start':
        text = {}
        call(["espeak", "-a 200 -v en+1" ,"Hello, user, please say a commmand"])
        main(text)
    else:
        call(["espeak", "-a 200 -v en+1 " ,"Did not recognize command, repeat please?"])

我能做些什么来纠正这个错误?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-04-17 06:41:38

正如注释中提到的,当您得到错误时,函数voice()将0返回到main()中的变量文本。该函数用于if 'hello' in text:。但是您不能在0上进行一个in测试,因为它是一个整数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71899439

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档