This question is related to my previous (unanswered) question: Running console program in PHP
The program I wrote in that question (progName.exe
) is actually a Windows Speech SDK application, which generates a .WAV file from a text file and computes some parameters from the text file. I simplified the Speech SDK program to this:
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;
CComPtr <ISpVoice> cpVoice;
CComPtr <ISpStream> cpWavStream;
CSpStreamFormat cAudioFmt;
hr = ::CoInitialize(NULL);
if (SUCCEEDED(hr))
hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&cpVoice);
if (SUCCEEDED(hr))
hr = cAudioFmt.AssignFormat(SPSF_22kHz16BitMono);
if (SUCCEEDED(hr))
hr = SPBindToFile(L"hello.wav", SPFM_CREATE_ALWAYS, &cpWavStream, &cAudioFmt.FormatId(), cAudioFmt.WaveFormatExPtr(), SPEI_PHONEME);
if (SUCCEEDED(hr))
hr = cpVoice->SetOutput(cpWavStream, TRUE);
if (SUCCEEDED(hr))
hr = cpVoice->Speak(L"Hello World", SPF_DEFAULT, NULL);
cpVoice->WaitUntilDone(INFINITE);
cpWavStream->Close();
cpVoice.Release();
return 0;
}
This code produces a .WAV file containing "Hello world". When it's run directly on the console of the server, it produces a correct .WAV file (around 60 kB). However, when it's called using a PHP script from a browser:
<?php
$cmd = "helloTTS.exe"; // The name of the program
exec($cmd);
?>
The program runs and finishes, but the produced .WAV file is only 46 bytes. But, if I use the PHP interactive mode in Windows (php -a
) to run the same script, the size of the .WAV file is correct.
Any idea about what could cause this? Why is the PHP script executed in the interactive mode different from the one executed from the browser?
Another question that might help me: which library (.DLL) is actually used by the functions such as ISpVoice::Speak()
? Is it SAPI.DLL
?