0

This is my Python Script:

from gtts import gTTS
from playsound import playsound

message = 'I'm Happy'

language = 'en'

speech = gTTS(text = message, lang = language, slow=False)

speech.save('test.mp3')

playsound('test.mp3')

print('Hi')

My goal is simple, I want it to be executed whenever I click a button in html. I've read that Ajax is needed to accomplish this. However, the script is different from other questions here, the others wanted to retrieve text from the python script; mine attempts to use google translate voice to say 'I'm happy'.

Alternatively, if I can make this happen through PHP, can I know how?

hideme
  • 1
  • 2
  • You want the sound to be played on server side or on client side? – Definitely not Rafal Apr 29 '21 at 11:36
  • @DefinitelynotRafal on the server side – hideme Apr 29 '21 at 11:54
  • Through PHP: [how to call a function on button click](https://stackoverflow.com/questions/45596799/button-element-onclick-to-run-javascript-function-without-jquery), [how to make an ajax call](https://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery), [how to generate mp3 (in case this one is outdated, create a new question)](https://stackoverflow.com/questions/14723973/text-to-speech-in-php-with-google-translate), [how to play sound on server](https://www.linuxquestions.org/questions/linux-software-2/php-play-sound-in-server-side-4175654933/) – Definitely not Rafal Apr 29 '21 at 12:11

0 Answers0