artificial-voice.py 874 B

12345678910111213141516171819202122232425262728
  1. from gtts import gTTS
  2. from playsound import playsound
  3. print('Virtual assistant:\n')
  4. txt = "Hello! How are you? Feeling good, bad, or okay?"
  5. voice = gTTS(text=txt, lang='en', slow=False)
  6. voice.save('1.mp3')
  7. playsound('1.mp3')
  8. response = input('You: ')
  9. if response.lower() == 'good':
  10. txt2 = "Great!"
  11. voice2 = gTTS(text=txt2, lang='en', slow=False)
  12. voice2.save('2.mp3')
  13. playsound('2.mp3')
  14. elif response.lower() == 'bad':
  15. txt2 = "Okay."
  16. voice2 = gTTS(text=txt2, lang='en', slow=False)
  17. voice2.save('2.mp3')
  18. playsound('2.mp3')
  19. elif response.lower() == 'ok':
  20. txt2 = 'Okay'
  21. voice2 = gTTS(text=txt2, lang='en', slow=False)
  22. voice2.save('2.mp3')
  23. playsound('2.mp3')
  24. else:
  25. txt2 = 'Dats invalid response bro!'
  26. voice2 = gTTS(text=txt2, lang='en', slow=False)
  27. voice2.save('2.mp3')
  28. playsound('2.mp3')