在 IIS 上通过 COM 将 SAPI 与 PHP 一起使用时出现问题


Problems using SAPI with PHP through COM, on IIS

我正在尝试通过COM对象使用Microsoft的SAPI在PHP中使文本到语音和语音识别在PHP中工作。

过去,我已经使用过这段代码来让TTS工作(Apache 2.1,PHP 5.5,在Windows 2003服务器上)

// 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接口来保存文件或类似的东西。