我试图通过COM对象使用Microsoft的SAPI在PHP中使用Text To Speech和Speech Recognition.
在过去,我已经使用此代码使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接口来保存文件或类似的东西.