简体   繁体   English

indentationerror 需要一个缩进的块函数

[英]indentationerror expected an indented block function

how can i have a problem.我怎么会有问题。 I'm doing the function that I can rerun我正在执行可以重新运行的功能

def sesver():
    r = sr.Recognizer()
    with sr.Microphone() as source:
      print("Bir sey de!")
      audio = r.listen(source)
    data = ""
    try:
      data = r.recognize_google(audio, language='tr-tr')
      data = data.lower()
      return data 
    except ValueError:

data = sesver()

You must add 4 spaces for indent .您必须为indent添加 4 个空格。

def sesver():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Bir sey de!")
        audio = r.listen(source)
        data = ""
        try:
            data = r.recognize_google(audio, language='tr-tr')
            data = data.lower()
            return data 
        except ValueError:
            pass

data = sesver()

Try this,尝试这个,

def sesver():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print 'Bir sey de!'
        audio = r.listen(source)
    data = ''
    try:
        data = r.recognize_google(audio, language='tr-tr')
        data = data.lower()
        return data
    except ValueError: # ':' was missing
        pass           # you pass or show exception message


data = sesver()

If you are new, try online indentations checkers.如果您是新手,请尝试在线缩进检查器。 It will help to create a clean indented code.这将有助于创建一个干净的缩进代码。

I'm assuming your code listing is incorrectly formatted and the function body is actually indented.我假设您的代码清单格式不正确并且函数体实际上是缩进的。 Your problem then is in except ValueError: .你的问题是在except ValueError: It expects an indented block after it.它期望在它之后有一个缩进的块。 If you simply want to ignore any ValueErrors, write pass in the indented block.如果您只想忽略任何 ValueErrors,请在缩进的块中写入pass

Write on top of code:写在代码之上:

import speech_recognition as sr

and into the terminal write:并进入终端写:

pip install SpeechRecognition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM