简体   繁体   中英

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 .

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: . It expects an indented block after it. If you simply want to ignore any ValueErrors, write pass in the indented block.

Write on top of code:

import speech_recognition as sr

and into the terminal write:

pip install SpeechRecognition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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