4

When I run the bingtest.py, I am getting the error below.

I have tried using the command

sudo pip install PyAudio

But it doesn't seem to work.

Traceback (most recent call last):
    File "bingtest.py", line 8, in <module>
     m = sr.Microphone()
    File "/usr/local/lib/python2.7/dist-
  packages/speech_recognition/__init__.py", line 79, in __init__
      self.pyaudio_module = self.get_pyaudio()
    File "/usr/local/lib/python2.7/dist-
  packages/speech_recognition/__init__.py", line 113, in get_pyaudio
  raise AttributeError("PyAudio 0.2.11 or later is required (found  
  version {})".format(pyaudio.__version__))
  AttributeError: PyAudio 0.2.11 or later is required (found version 0.2.8)

bingtest.py

#!/usr/bin/env python3

# NOTE: this example requires PyAudio because it uses the Microphone 
class
import os
import speech_recognition as sr
import time
r = sr.Recognizer()
m = sr.Microphone()

def callback(recognizer,audio):
BING_KEY = "xxxxxx" # Microsoft Bing Voice Recognition
try:
    var=r.recognize_bing(audio, key=BING_KEY)
    print("audio listened...")
    print("Microsoft Bing Voice Recognition thinks you said " + var)
    if(var=="open chrome"):
        os.system("google-chrome")
except sr.UnknownValueError:
    print("Microsoft Bing Voice Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
return

def call_bing():
# obtain audio from the microphone

  with m as source:
    print ("say something:")
    r.adjust_for_ambient_noise(source)
  stop_listening = r.listen_in_background(m,callback)
  for _ in range(60): time.sleep(0.1)
  stop_listening()

call_bing()
print "returned to main from bing function"
call_bing()
call_bing()
CDspace
  • 2,639
  • 18
  • 30
  • 36
Mikasa
  • 321
  • 7
  • 16

1 Answers1

0

try this also. first you have to install PyAudio and then upgrade it using pip

sudo pip install PyAudio
pip install --upgrade PyAudio
lashiniDW
  • 11
  • 2