0

I am creating a project that requires the SpeechRecognition library and I have it all installed and whatnot but everytime I run the program... the program doesn't transcribe what I am saying and it doesn't throw any errors either.

Here Is My Code

import speech_recognition as sr

r=sr.Recognizer()
print(sr.Microphone.list_microphone_names())
with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source,duration=1)
    # r.energy_threshold()
    print("say anything : ")
    audio= r.listen(source)
    try:
        text = r.recognize_google(audio)
        print(text)
    except:
        print("sorry, could not recognise")

Output

['Background Music', 'Background Music (UI Sounds)', 'MacBook Air Microphone', 'MacBook Air Speakers', 'Iriun Webcam Audio', 'EpocCam Microphone']
say anything : 
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Vasu Bansal
  • 41
  • 1
  • 6
  • Did you try manually setting `device_index` in `Microphone()` to the index of `MacBook Air Microphone`? Otherwise it uses your system default, which may or may not be an actual microphone; I'm not certain how that all works on Mac OS but you should try explicitly choosing the microphone and seeing if that works. That'd be my first troubleshooting step. Based on the `list_microphone_names` output, it seems like the index is 2, so you can try `sr.Microphone(device_index=2)` and see if that works. – Random Davis Feb 09 '21 at 18:23
  • I tried that but it is giving me this error ```Unexpected keyword argument 'default_index' in constructor call``` – Vasu Bansal Feb 09 '21 at 19:44
  • That's because you wrote `default_index` instead of `device_index`. – Random Davis Feb 09 '21 at 19:45
  • nope not working :( Its still doing the same problem of not transcripting or anything – Vasu Bansal Feb 09 '21 at 19:46
  • Did you take a look at the solutions in this post? https://stackoverflow.com/questions/32005310/speech-recognition-python-code-not-working – Random Davis Feb 09 '21 at 19:57
  • Yes I tried but none of them worked – Vasu Bansal Feb 09 '21 at 20:17
  • Well, that library was last updated 2 years ago, which is a pretty long time, so maybe try using another library that's more up-to-date? – Random Davis Feb 09 '21 at 20:22
  • Do you have any idea of another library.. – Vasu Bansal Feb 09 '21 at 21:15
  • I don't have a suggestion; I know general Python but nothing about speech recognition in particular. And StackOverflow generally doesn't allow questions where someone is asking for a library recommendation. I can only recommend that you research and try out alternatives, or see if anyone else using this library is having the same issue and what they did to fix their problem. – Random Davis Feb 09 '21 at 21:42

0 Answers0