Last active
May 26, 2020 15:26
-
-
Save pradeepradyumna/8894feffe21bd9244079e7df096adb0a to your computer and use it in GitHub Desktop.
Speech Recognizer Python Script
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
import speech_recognition as sr | |
import playsound | |
from gtts import gTTS | |
def speak(text): | |
tts = gTTS(text=text, lang="en") | |
filename = "voice.mp3" | |
tts.save(filename) | |
print("playing..." + text) | |
playsound.playsound(filename) | |
r = sr.Recognizer() | |
with sr.Microphone() as source: | |
print('Speak something...') | |
audio = r.listen(source) | |
try: | |
text = r.recognize_google(audio) | |
print('You said : ' + str(text)) | |
speak(text) | |
except Exception as e: | |
print("Sorry, didn't recognize your voice") | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This program recognizes the user's speech and repeats it using Google API