0

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?

Community
  • 1
  • 1
ArthurN
  • 169
  • 4
  • 14

1 Answers1

0

When PHP is running as a service, it's running as a different user and with different registry keys than it has when running interactively. In particular, SAPI makes extensive use of the registry to determine the voice to load. I suspect that you're using the desktop TTS engine, which isn't designed to run as a service. You will have much better results with the Microsoft Speech Platform SDK 11, which is designed to run from service applications, and which uses the same SAPI programming interface. (It has different voices, and is configured slightly differently. The SDK has samples that outline the differences.)

Eric Brown
  • 13,308
  • 7
  • 28
  • 67