PHP wrapper for microsoft SAPI

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
legojedi
Forum Newbie
Posts: 3
Joined: Sun Jul 29, 2007 10:06 am

PHP wrapper for microsoft SAPI

Post by legojedi »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I can not figure out the reason why this does not go past step 2, it will not go to 2a.  Any help would be greatly appreciated.  The ultimate goal here is to save a text to speech into a wav or mp3 file.

Code: Select all

<?php
   $Engine = new COM("SAPI.SpVoice");
   $File = new COM("SAPI.SpFileStream");

   echo "1</br>";   

   $File->Open("C:\\Website\\Test\\5.wav", 3, false);
   
   echo "2</br>";
   
   $Engine->AllowOutputFormatChangesOnNextSet = false;
   
   echo "2a</br>";
      
   $Engine->SetOutput($File,true);
   
   echo "2b</br>";
   
   $Engine->SetOutput($File);

   echo "3</br>";
   
   $Engine->Speak("Hello World!", SPF_DEFAULT);
   
   echo "4</br>";

   $File->Close();
   
   echo "5</br>";
   
   $File->Close();
   unset($File);
   unset($Engine);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: PHP wrapper for microsoft SAPI

Post by superdezign »

legojedi wrote:I can not figure out the reason why this does not go past step 2, it will not go to 2a.
Do you have error_reporting turned on?
legojedi
Forum Newbie
Posts: 3
Joined: Sun Jul 29, 2007 10:06 am

Post by legojedi »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I put in a try catch to get the error message, on that line it could not find the function.  Looking at the very "helpful" msn docs for the SAPI, I noticed that I had already set that value in the $File->Open line.  I have adjusted my code now as per your suggestions and now it does not go to 2b, nor do I get any error message and never run is not printed.

Code: Select all

<?php
	$Engine = new COM("SAPI.SpVoice");
	$File = new COM("SAPI.SpFileStream");

	echo "1</br>";	

	$File->Open("C:\\Website\\Test\\5.wav", 3, false);
	
	echo "2</br>";
	
	echo "2a</br>";
		
	try 
	{
	$Engine->SetOutput($File,true);
	}
	catch (Exception $e)
	{
		echo 'Caught exception: ',  $e->getMessage(), "\n";
                        echo "never run";
	}
	
	echo "2b</br>";
	
	$Engine->SetOutput($File);

	echo "3</br>";
	
	$Engine->Speak("Hello World!", SPF_DEFAULT);
	
	echo "4</br>";

	$File->Close();
	
	echo "5</br>";
	
	$File->Close();
	unset($File);
	unset($Engine);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

legojedi wrote:I put in a try catch to get the error message, on that line it could not find the function. Looking at the very "helpful" msn docs for the SAPI, I noticed that I had already set that value in the $File->Open line. I have adjusted my code now as per your suggestions and now it does not go to 2b, nor do I get any error message and never run is not printed.
Error reporting and exceptions are not the same. Are you sure that the failing function throws an exception upon failure, or does it just trigger an error?

Again, turn on error_reporting.
legojedi
Forum Newbie
Posts: 3
Joined: Sun Jul 29, 2007 10:06 am

Post by legojedi »

Sorry i thought they were the same, googled it and now I have error reporting on. As per my error log, it is calling an undefined method. However, when I look at the API http://msdn2.microsoft.com/en-us/library/ms723597.aspx it is a function for SpVoice and it has two parameters.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

Superdiz what is that error_reporting turned on? I thought error_reporting has integer value indicating the level of errors displayed. Do you mean display_errors turned on?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

miro_igov wrote:Superdiz what is that error_reporting turned on? I thought error_reporting has integer value indicating the level of errors displayed. Do you mean display_errors turned on?
No. Error reporting implies both, because either could be disabled. I assumed that any internet search he'd do for error reporting would show him both.
legojedi wrote:Sorry i thought they were the same, googled it and now I have error reporting on. As per my error log, it is calling an undefined method. However, when I look at the API http://msdn2.microsoft.com/en-us/library/ms723597.aspx it is a function for SpVoice and it has two parameters.
Are you sure everything is loaded okay? And are you positive there are no spelling mistakes?
Post Reply