Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. # Vaatii pip-asennukset
  2.  
  3. # sudo pip install PyAudio
  4. # sudo pip install SpeechRecognition
  5.  
  6. import speech_recognition as sr
  7.  
  8. r = sr.Recognizer()
  9. with sr.Microphone() as source:
  10. r.adjust_for_ambient_noise(source) # Kuuntelee sekunnin ja yrittää päätellä taustamelun tason
  11. audio = r.listen(source) # Äänittää, kunnes kokee, että äänitaso on palannut peruslukemile
  12.  
  13. try:
  14.  
  15. text = r.recognize_google(audio) # Pyytää Googlea muuttamaan äänen tekstiksi
  16.  
  17. except sr.UnknownValueError:
  18.  
  19. # Äänestä ei saatu selvää
  20.  
  21. pass
  22.  
  23. except sr.RequestError:
  24.  
  25. # Yhteyttä Googleen ei saatu muodostettua
  26.  
  27. pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement