在PHP运行Windows语音SDK应用程序 [英] Running Windows Speech SDK application in PHP

查看:171
本文介绍了在PHP运行Windows语音SDK应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是关系到我的previous(解答)问题:运行控制台程序PHP

This question is related to my previous (unanswered) question: Running console program in PHP

我这个问题写的程序( progName.exe )实际上是一个Windows语音SDK应用程序,产生从文本文件.wav文件,并计算一些参数从文本文件。我简化了语音SDK程序如下:

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

这code生成一个包含Hello World的.wav文件。当它的服务器的控制台上直接运行,它会产生一个正确的.wav文件(大约60 KB)。然而,当它的使用PHP脚本从浏览器名为:

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);
?>

该程序运行和完成,但产生的.WAV文件只有46字节。但是,如果我使用的PHP交互模式在Windows( PHP -a )来运行相同的脚本,.WAV文件的大小是正确的。

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.

什么可能导致此任何想法?为什么PHP脚本从浏览器中执行一个不同的交互模式执行的?

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?

另一个问题,可以帮助我:哪个库(.dll)的实际使用功能,如 ISpVoice ::说话()?它是 SAPI.DLL

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

推荐答案

当PHP运行作为一种服务,它的运行作为不同的用户,并与比它交互方式运行时,不同的注册表项。特别是,SAPI广泛使用注册表来确定声音加载。我怀疑你正在使用的桌面TTS引擎,它的目的不是要作为服务运行。你将不得不与微软语音平台SDK 11 ,其目的是从服务应用程序运行,并使用相同的SAPI编程接口。 (它具有不同的声音,并且被构造略有不同。该SDK具有轮廓的差异的样品。)

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.)

这篇关于在PHP运行Windows语音SDK应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆