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)
$VoiceObj = new COM("SAPI.SpVoice") or die("Unable to instantiate SAPI");
$VoicesToken=$VoiceObj->GetVoices();
$NumberofVoices=$VoicesToken->Count;
for($i=0;$i<$NumberofVoices;$i++)
{
$VoiceToken=$VoicesToken->Item($i);
$VoiceName[$i]=$VoiceToken->GetDescription();
}
$SelectedVoiceToken=$VoicesToken->Item(0);
$SelectedVoiceTokenid=$SelectedVoiceToken->id;
$VoiceObj->Voice=$SelectedVoiceToken;
$VoiceName=$VoiceObj->Voice->GetDescription();
$VoiceFile = new COM("SAPI.SpFileStream");
$VoiceFile->Open('./test.wav', 3, false);
$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:
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?
source
share