Skip to content

Instantly share code, notes, and snippets.

@pradeepradyumna
Last active May 26, 2020 15:26
Show Gist options
  • Save pradeepradyumna/8894feffe21bd9244079e7df096adb0a to your computer and use it in GitHub Desktop.
Save pradeepradyumna/8894feffe21bd9244079e7df096adb0a to your computer and use it in GitHub Desktop.
Speech Recognizer Python Script
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)
@pradeepradyumna
Copy link
Author

This program recognizes the user's speech and repeats it using Google API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment