Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ======================================================
- # speechrec-test.py
- # ------------------------------------------------------
- # written by G.D. Walters
- # for Full Circle Magazine #153
- # ------------------------------------------------------
- # Borrowed from speechrecognition library __main__.py
- # ======================================================
- import speech_recognition as sr
- r = sr.Recognizer()
- m = sr.Microphone()
- loop = True
- while loop:
- try:
- print('Silence!!!!!!!!!!')
- with m as source:
- r.adjust_for_ambient_noise(source)
- while True:
- print('SPEAK HUMAN...')
- with m as source:
- audio = r.listen(source)
- print('Quiet while I think...')
- try:
- value = r.recognize_google(audio)
- if str is bytes:
- print(f'You said "{value.encode("utf-8")}"')
- else:
- print(f'You said "{value}"')
- if (value == 'please quit') or (value == 'please stop'):
- print('Program ends...')
- loop = False
- break
- except sr.UnknownValueError:
- print('try that again')
- except sr.RequestError as e:
- print('unable to get requests from engine')
- except KeyboardInterrupt:
- loop = False
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement