From 2fc3b9678e3a54bffd5148061d839b42758bc726 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Luz Date: Sun, 26 Jul 2020 14:54:15 -0300 Subject: [PATCH] speech_to_text done --- projects/Speech to text/requirements.txt | 2 ++ projects/Speech to text/speech_to_text.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 projects/Speech to text/requirements.txt create mode 100644 projects/Speech to text/speech_to_text.py diff --git a/projects/Speech to text/requirements.txt b/projects/Speech to text/requirements.txt new file mode 100644 index 000000000..cf7df4505 --- /dev/null +++ b/projects/Speech to text/requirements.txt @@ -0,0 +1,2 @@ +PyAudio==0.2.11 +SpeechRecognition==3.8.1 diff --git a/projects/Speech to text/speech_to_text.py b/projects/Speech to text/speech_to_text.py new file mode 100644 index 000000000..8a9ac156d --- /dev/null +++ b/projects/Speech to text/speech_to_text.py @@ -0,0 +1,23 @@ +import speech_recognition + +def record_voice(): + microphone = speech_recognition.Recognizer() + + with speech_recognition.Microphone() as live_phone: + microphone.adjust_for_ambient_noise(live_phone) + + print("I'm trying to hear you: ") + audio = microphone.listen(live_phone) + try: + phrase = microphone.recognize_google(audio, language='en') + return phrase + except speech_recognition.UnkownValueError: + return "I didn't understand what you said" + +if __name__ == '__main__': + phrase = record_voice() + + with open('you_said_this.txt','w') as file: + file.write(phrase) + + print('the last sentence you spoke was saved in you_said_this.txt')