Problems using SAPI with PHP over COM in IIS

I am trying to get Text To Speech and Speech Recognition to work in PHP using Microsoft SAPI through COM objects.

In the past, I have already used this code to get TTS to work (Apache 2.1, PHP 5.5, on 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();

In my new setup (IIS 7.5, PHP 7.0, Windows Server 2008R2), the same code crashes

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

With such small details (where to get more?) I cannot understand what the problem is.

Check write permissions. PHP 7.0 replaced by 5.5, still not working. The same code was tested using the Win32 application, and it works flawlessly.

Any clues?

+4
source share
1 answer

.

PHP COM- ,

, , IIS, . : COM - .

0

Source: https://habr.com/ru/post/1627733/


All Articles