我正在尝试通过 COM 对象使用 Microsoft 的 SAPI 使文本到语音和语音识别在 PHP 中工作。
过去,我已经使用此代码让 TTS 工作(Apache 2.1、PHP 5.5、Windows 2003 Server)
// Instantiate the object
$VoiceObj = new COM("SAPI.SpVoice") or die("Unable to instantiate SAPI");
// Get the available voices
$VoicesToken=$VoiceObj->GetVoices();
$NumberofVoices=$VoicesToken->Count;
for($i=0;$i<$NumberofVoices;$i++)
{
$VoiceToken=$VoicesToken->Item($i);
$VoiceName[$i]=$VoiceToken->GetDescription();
}
// Get and print the id of the specified voice
$SelectedVoiceToken=$VoicesToken->Item(0);
$SelectedVoiceTokenid=$SelectedVoiceToken->id;
// Set the Voice
$VoiceObj->Voice=$SelectedVoiceToken;
$VoiceName=$VoiceObj->Voice->GetDescription();
$VoiceFile = new COM("SAPI.SpFileStream");
$VoiceFile->Open('./test.wav', 3, false);
// Speak to file
$VoiceObj->AudioOutputStream = $VoiceFile;
$VoiceObj->Speak("What an unbelievable test", 0);
$VoiceFile->Close();
在我的新设置(IIS 7.5、PHP 7.0、Windows Server 2008R2)上,相同的代码在
$VoiceObj->Speak("What an unbelievable test", 0);
Fatal error: Uncaught com_exception: <b>Source:</b> Unknown<br/><b>Description:</b> Unknown in \\web\tts.php:30 Stack trace: #0 \\web\tts.php(30): com->Speak('this is a marve...', 0) #1 {main}
这么小的细节(在哪里检索更多?)我无法弄清楚问题可能是什么。
已检查写入权限。
PHP 7.0 替换为 5.5,还是不行。
使用 Win32 应用程序测试的相同代码,它可以完美运行。
任何提示?
最佳答案
两年后,我无意中找到了这个问题的答案。
PHP COM 对象无法在网络路径上执行文件操作,即使具有所有必需的权限
一旦将开发文件夹移动到运行 IIS 的同一台机器上,一堆以前损坏的测试就开始工作了。他们都有一个共同点:他们使用 COM 接口(interface)来保存文件或类似的东西。
关于php - 在 IIS 上通过 COM 将 SAPI 与 PHP 一起使用的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35263837/