Skip to content

Instantly share code, notes, and snippets.

@harendra21
Last active August 12, 2021 04:38
Show Gist options
  • Save harendra21/02d19fadf3004f33ffb09b4481d02bbe to your computer and use it in GitHub Desktop.
Save harendra21/02d19fadf3004f33ffb09b4481d02bbe to your computer and use it in GitHub Desktop.

Python 3 speech recognition (speech to text)

For speech recognition we need to install SpeechRecognition package via PIP

pip install SpeechRecognition

After installing the package we need to copy and paste following code an run our program

import speech_recognition as sr
# importing pachage
r=sr.Recognizer()
print(sr.Microphone.list_microphone_names())
# checking for microphone
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment