Created
October 26, 2016 13:06
-
-
Save nomelif/cc24d8aad12bf7cd5b4def19f715b456 to your computer and use it in GitHub Desktop.
This file contains 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
# Vaatii pip-asennukset | |
# sudo pip install PyAudio | |
# sudo pip install SpeechRecognition | |
import speech_recognition as sr | |
r = sr.Recognizer() | |
with sr.Microphone() as source: | |
r.adjust_for_ambient_noise(source) # Kuuntelee sekunnin ja yrittää päätellä taustamelun tason | |
audio = r.listen(source) # Äänittää, kunnes kokee, että äänitaso on palannut peruslukemile | |
try: | |
text = r.recognize_google(audio) # Pyytää Googlea muuttamaan äänen tekstiksi | |
except sr.UnknownValueError: | |
# Äänestä ei saatu selvää | |
pass | |
except sr.RequestError: | |
# Yhteyttä Googleen ei saatu muodostettua | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment