none
Running Windows Speech SDK program in PHP

    Question

  • I wrote a simple code to generate a .WAV file from a hard-coded text ("Hello world") using Speech SDK. Here's my code:

    #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;
    }

    If I run the program directly on the console on a server, it produces a correct .WAV file (about 60 kB). However, if I call the program in a PHP script:

    <?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. Why does this happen?

    Update: I tried to run the PHP script using PHP interactive mode in Windows (php -a), and the program works correctly; the size of the .WAV file is 60 kB.

    A question that might help me: which library (.DLL) is actually called by the functions such as ISpVoice::Speak()? Is it SAPI.DLL?


    • Edited by ThurN Tuesday, September 24, 2013 12:47 PM
    Monday, September 23, 2013 2:28 PM