0

So i'm working in python with SpeechRecognition : https://pypi.python.org/pypi/SpeechRecognition/ It works perfectly with this code:

import pyaudio
import speech_recognition as sr
r = sr.Recognizer(language = "es-ES", key = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw")
with sr.Microphone() as source:
    audio = r.listen(source)
print r.recognize(audio)

But when I try to turn it into a function:

def stt():
    r = sr.Recognizer(language = "es-ES", key = "AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw")
    with sr.Microphone() as source:
        audio = r.listen(source)
    return r.recognize(audio)

I get this error: File "./prueba_2.py", line 22 with sr.Microphone() as source: ^ IndentationError: unindent does not match any outer indentation level How could i fix it?

  • Fix indentation in your script. In Python it is important. See http://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level – Nikolay Shmyrev Mar 22 '15 at 18:28
  • If ``key`` variable is an API key of some kind, for some external servise, it might be wise to generate new keys, and delete these, I think you shouldn't have posted them. – jb. Mar 22 '15 at 19:15

0 Answers0