Glenn, couple of things come to mind.

1. SAPI_FileObject:=CreateOLEObject('SAPI.SpFileStream').  Could it be that 
'SAPI.SpFileStream' should be something else?  You're assigning to a variant, 
so there's no strong typing. 

2. Maybe you need to do something like 

   SAPI_OLEObject.CreateAudioOutputStream;

Jeremy


-----Original Message-----
From: advanced_delphi@yahoogroups.com on behalf of Glenn Lawler
Sent: Fri 2/13/2009 4:38 PM
To: advanced_delphi@yahoogroups.com
Subject: [advanced_delphi] Redirect Speech API (SAPI) Text to Speech to a WAV 
file
 
We use SAPI for text to speech in a number of utility
programs and embedded in a number of applications we
provide to our customer base.

I recently had an opportunity which would be
enhanced if we could save the audio output of
text to speech to a WAV file.

I Did a little research and found that SAPI does indeed
have that capability. (see:
http://msdn.microsoft.com/en-us/library/ms723597(VS.85).aspx
)

Here is a short code stub of what we are doing:

--------------------------
var
  SAPI_OLEObject: variant;
  SAPI_FileObject: variant;
  ErrorMsg: string;

try
  SAPI_FileObject:=CreateOLEObject('SAPI.SpFileStream');
  except
    on E: Exception do begin
      ErrorMsg:='Error creating SAPI File: ' + E.Message;
      end;
    end;

try
  SAPI_FileObject.Open('O:\TMP\Test.wav',SSFMCreateForWrite,False);
  except
    on E: Exception do begin
      ErrorMsg:='Error opening SAPI File: ' + E.Message;
      end;
    end;

try
  SAPI_OLEObject:=CreateOLEObject('SAPI.SpVoice');
  except
    on E: Exception do begin
      ErrorMsg:='Error opening Speech API: ' + E.Message;
      end;
    end;

try
  SAPI_OLEObject.AudioOutputStream:=SAPI_FileObject;
  except
    on E: Exception do begin
      ErrorMsg:='Error assigning SAPI_FileObject: ' + E.Message;
      end;
    end;
--------------------------

The code goes on to call SAPI_OLEObject.Speak(FName,Flags);
to speak the text. The error occurs in the last block on:

  SAPI_OLEObject.AudioOutputStream:=SAPI_FileObject;

ErrorMsg = 'Error assigning SAPI_FileObject: Member not found'

First thing I did was Google: Delphi AudioOutputStream
and found that many others have had this same problem. I came
up with a lot of postings on this exact error, but no one who
had figured out how to fix the problem. It would seem that
"Member not found" means that AudioOutputStream is not a valid
property of object created with the OLE string 'SAPI.SpVoice',
however, the documentation from Microsoft seems clear that it
is a property. I am using the SAPI that ships with Vista Business,
so I believe I should have a new enough version.

We have done quite a bit with OLE automation of MS Office and
a lot of other things, and I have run into many situations
where you need to do things slightly differently in Delphi than
you would do in other languages, like VB, for example. I am
guessing this might be one of those cases.

Does anyone have any experience with redirecting SAPI output
to a WAV file?

Glenn Lawler
www.incodesystems.com



<<winmail.dat>>

Reply via email to