Created
December 27, 2022 07:31
-
-
Save bbence84/04d1935a92a4b4ab3d44bf182ea4bcc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import speech_recognition as sr | |
from preferredsoundplayer import playsound | |
def start_listening(): | |
r = sr.Recognizer() | |
r.dynamic_energy_threshold = True | |
r.energy_threshold = 100 | |
r.pause_threshold = 0.7 | |
while(1): | |
try: | |
with sr.Microphone(device_index = 0) as source: | |
r.dynamic_energy_threshold = True | |
r.energy_threshold = 100 | |
r.pause_threshold = 0.7 | |
r.adjust_for_ambient_noise(source, duration=0.2) | |
print("Say something!") | |
audio = r.listen(source) | |
spokenText = r.recognize_google(audio, show_all=False) | |
print("Text recognized: ", spokenText) | |
playsound("CantinaBand3.wav",block=True) | |
except sr.RequestError as e: | |
print("Request error; {0}".format(e)) | |
except sr.UnknownValueError as e: | |
print("Unknown error occurred: {0}".format(e)) | |
playsound("CantinaBand3.wav",block=True) | |
def main(): | |
start_listening() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment