Advertisement
fr0stn1k

English version of speech_recognition and syntesis

Dec 18th, 2020
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import speech_recognition as sr
  2. import pyttsx3
  3.  
  4. r = sr.Recognizer()
  5. with sr.Microphone() as source:
  6.     print('Скажите что-нибудь...')
  7.     audio = r.listen(source)
  8.  
  9. #try:
  10.     # for testing purposes, we're just using the default API key
  11.     # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
  12.     # instead of `r.recognize_google(audio)`
  13. #    print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
  14. #except sr.UnknownValueError:
  15. #    print("Google Speech Recognition could not understand audio")
  16. #except sr.RequestError as e:
  17. #    print("Could not request results from Google Speech Recognition service; {0}".format(e))
  18.  
  19.  
  20. #query = r.recognize_google(audio, language="ru-RU")
  21. query = r.recognize_google(audio)
  22. print('Вы сказали ' + query.lower())
  23.  
  24. # Синтезатор речи
  25. engine = pyttsx3.init()
  26. voices = engine.getProperty('voices')
  27. #engine.setProperty('voice', 'ru')
  28. engine.setProperty('voice', voices[0].id)
  29. engine.say(query)
  30. engine.runAndWait()
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement