artificial-voice.py 921 B

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