Page 1 of 1

PHP wrapper for microsoft SAPI

Posted: Sun Jul 29, 2007 10:10 am
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]

Re: PHP wrapper for microsoft SAPI

Posted: Sun Jul 29, 2007 10:18 am
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?

Posted: Sun Jul 29, 2007 10:31 am
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]

Posted: Sun Jul 29, 2007 10:34 am
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.

Posted: Sun Jul 29, 2007 10:56 am
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.

Posted: Sun Jul 29, 2007 1:27 pm
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?

Posted: Sun Jul 29, 2007 6:28 pm
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?