Advertisement
Embry0

Untitled

Oct 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import os
  2. import speech_recognition as sr
  3. import playsound
  4. from gtts import gTTS
  5.  
  6.  
  7. def speak_to_me(text):
  8.     tts = gTTS(text=text, lang='en')
  9.     filename = 'f_voice.mp3'
  10.     tts.save(filename)
  11.     playsound.playsound(filename)
  12.  
  13.  
  14. def get_audio_from_me():
  15.     r = sr.Recognizer()
  16.     with sr.Microphone() as source:
  17.         audio = r.listen(source)
  18.         said = ''
  19.  
  20.         try:
  21.             said = r.recognize_google(audio)
  22.             print(said)
  23.         except Exception as e:
  24.             print("Exception: " + str(e))
  25.  
  26.     return said
  27.  
  28.  
  29. speak_to_me('thunder hit you')
  30. my_text = get_audio_from_me()
  31.  
  32. if "hello" in my_text:
  33.     speak_to_me("hello how are you")
  34. else:
  35.     speak_to_me("I don`t understand try again please")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement