diff --git a/Code-Sleep-Python/speech-to-text/README.md b/Code-Sleep-Python/speech-to-text/README.md new file mode 100644 index 0000000..3fc2dbe --- /dev/null +++ b/Code-Sleep-Python/speech-to-text/README.md @@ -0,0 +1,39 @@ +# Speech-To-Text + +Simple Script to get User input from microphone and use Google's API to transform into text. + +# Installation + +Install python-pyaudio: + +``` +sudo apt-get install python-pyaudio +``` + +Install portaudio: + +``` +sudo apt-get install portaudio19-dev +``` + +Sadly, the PyAudio is not updated and doesn't work on the latest version of Python3 so: + +``` +virtualenv -p python2.7 req +source req/bin/activate +pip install PyAudio +pip install SpeechRecognition +``` + +# Test the app: + +``` +source req/bin/activate +python stt.py +``` + +# TODO: + +- Find a way to make this work for Python3. + +- Add new recognition APIs. \ No newline at end of file diff --git a/Code-Sleep-Python/speech-to-text/requirements.txt b/Code-Sleep-Python/speech-to-text/requirements.txt new file mode 100644 index 0000000..cf7df45 --- /dev/null +++ b/Code-Sleep-Python/speech-to-text/requirements.txt @@ -0,0 +1,2 @@ +PyAudio==0.2.11 +SpeechRecognition==3.8.1 diff --git a/Code-Sleep-Python/speech-to-text/stt.py b/Code-Sleep-Python/speech-to-text/stt.py new file mode 100644 index 0000000..72baba0 --- /dev/null +++ b/Code-Sleep-Python/speech-to-text/stt.py @@ -0,0 +1,14 @@ +import speech_recognition as sr + +r = sr.Recognizer() + +with sr.Microphone() as source: + print("Say something... ") + audio = r.listen(source) + +try: + print("Google thinks you said: {}".format(r.recognize_google(audio))) +except sr.UnkownValueError: + print("Couldn't understand") +except sr.RequestError as e: + print("Couldn't request results; {}".format(e))