1

Respected, I have python code gTTS

from gtts import gTTS
import os
fh=open("test.txt","r")
mytext=fh.read().replace("\n","")
language="en"
output=gTTS(text=mytext, lang=language,slow=False) 
output.save("output.mp3")
fh.close()
os.system("start output.mp3")

save as in folder htdocs/website/text_to_speech.py My question is that it's run perfect on IDE python and execute output.mp3 file i want to excute this file using php my php code is

$output = shell_exec("text_to_speech.py");
echo $output;

when i run this code on php nothing execute file output Looking forward for your kind support Thank you

Hashaam zahid
  • 315
  • 5
  • 21
  • Are there any errors? Is `shell_exec()` enabled on the server (*Do not recommend this*)? Is the path to the python script the correct one? – Darren Jun 15 '23 at 01:52
  • 1
    I know nothing about Python but the usual way to execute external scripts is by either calling the interpreter before the script or adding it inside the script and then adding the executable flag to the script. So, if you go with the first option your shell_exec call should be something like `shell_exec('/full_path_to/python /full_path_to/text_to_speech.py')` (of course you replace full_path_to with the correct path to the script and interpreter) – Sledge Hammer Jun 15 '23 at 02:57
  • Do you please tell me how to write full path my file in c:xamp/htdocs/python/text_to_speech.py in php shell_exec function thank you – Hashaam zahid Jun 15 '23 at 07:16
  • Sorry, but I haven't used PHP on Windows. Try these two links for more info about file paths in Windows. https://www.php.net/manual/en/wrappers.file.php https://stackoverflow.com/questions/2334510/help-with-windows-path-php Also do not forget to add the full path to python.exe – Sledge Hammer Jun 15 '23 at 07:39

0 Answers0