I have Apache2.4 running on a Windows Server 2019 VM. Apache is set up so I can use python in my cgi-bin scripts. I have a script that does
#!C:/Python39/python.exe
text = "This is some example text."
engine = pyttsx3.init("sapi5")
engine.save_to_file(text, "test.wav")
engine.runAndWait()
print("Content-type: audio/wav")
print()
with open("test.wav", "rb") as file:
print(file.read())
If I call that script from the command line, it creates a 115kb file that contains the spoken version of my text. However, if I invoke that same script via a web browser (i.e., by browsing to http://whatever/cgi-bin/test.py) it instead creates a 46b file that has what appears to be a valid WAV header, but no actual data -- that is, it's created a valid empty sound file. There are no errors raised that I can see, neither written to the screen, in apache's error log, nor in Windows Logs, so far as I have been able to tell.
(The same code appears to work when running WAMP on a Windows 10 machine on my local network. I've also tried installing PHP and having Apache use that to call Python is a shell command, which makes no difference. (I don't know why I thought it would!))
How can I make this work the same under cgi/Apache as it does from the command line?
I don't know if this is useful information, but here are the versions of some of the things installed on these machines (ETA, I've tried upgrading on Windows 10 to better match Windows Server 2019):
WINDOWS 10
HTTPD: 2.4.35 Upgraded to 2.4.48, still works
PHP: PHP Version 7.2.10 (but Python is being called as CGI in my test, so this shouldn't matter) Upgraded to 8.0.6, still works
PYTHON: 3.9.2rc1 (tags/v3.9.2rc1:4064156, Feb 17 2021, 11:25:18) [MSC v.1928 64 bit (AMD64)] Upgraded to 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)], still works
.NET: Running "Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version" produces:
PSChildName Version
----------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.04084
Full 4.8.04084
Client 4.0.0.0
SERVER 2019
HTTPD: 2.4.48
PHP: PHP Version 8.0.9 (but Python is being called as CGI in my test, so this shouldn't matter)
PYTHON: 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]
.NET: Running "Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version" produces:
PSChildName Version
----------- -------
v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.03761
Full 4.8.03761
Client 4.0.0.0
from On Windows Server 2019, pyttsx3 called via cgi/Apache produces empty wav files
No comments:
Post a Comment