SpeechRecognition作为一种功能

时间:2015-03-22 16:50:19

标签: python function speech-recognition

所以我使用SpeechRecognition在python中工作:https://pypi.python.org/pypi/SpeechRecognition/ 它与此代码完美配合:

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)

但是当我试图把它变成一个函数时:

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

我收到此错误:File "./prueba_2.py", line 22 with sr.Microphone() as source: ^ IndentationError: unindent does not match any outer indentation level 我怎么能解决它?

0 个答案:

没有答案