Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
__使用google';输入_;error;s语音api Python 3_Python_Google Api_Speech Recognition_Gtts - Fatal编程技术网

__使用google';输入_;error;s语音api Python 3

__使用google';输入_;error;s语音api Python 3,python,google-api,speech-recognition,gtts,Python,Google Api,Speech Recognition,Gtts,我正在使用谷歌的API用python做一个语音识别器项目。代码如下: from gtts import gTTS import speech_recognition as sr def get_audio(): r = sr.Recognizer() with sr.Microphone as source: l = r.listen(source) said = "" try: said =

我正在使用谷歌的API用python做一个语音识别器项目。代码如下:

from gtts import gTTS
import speech_recognition as sr

def get_audio():

    r = sr.Recognizer()

    with sr.Microphone as source:

        l = r.listen(source)

        said = ""

        try:

            said = recognize_google(l)

            print(said)

        except Exception as e:

            print("Exception: " + str(e))

        return said
get_audio()
错误是:

<ipython-input-5-73a42a1f9208> in get_audio()
      1 def get_audio():
      2     r = sr.Recognizer()
----> 3     with sr.Microphone as source:
      4         l = r.listen(source)
      5         said = ""

AttributeError: __enter__
在get\u audio()
1 def get_audio():
2 r=高级识别器()
---->3以高级话筒为声源:
4 l=r.监听(源)
5说:“”
AttributeError:\u输入__
有人能解释一下原因吗?一个人的电脑上运行着相同的代码。

使用

with sr.Microphone() as source:
   ...

注意括号:这是一个函数调用。

您的麦克风设置正确吗?您可以使用Python保存/录制音频吗?