[fpc-pascal] SpVoice.GetVoices returned exception class EOleSysError

Andrew Haines andrewd207 at aol.com
Tue Apr 11 21:23:32 CEST 2017

On 04/10/2017 02:58 AM, misabov wrote:
> The project has generated an exception class EOleSysError with a message:
> ???? ?????? ?? ??????.
> uses
> ...,ComObj;
> var
> SpVoice: Variant;
> SpVoice := CreateOleObject('SAPI.SpVoice');
> SpVoice.Voice:= SpVoice.GetVoices('','').Item(0);
> SpVoice GetVoices method (SAPI 5.3) cannot return  a selection of voices
> available to the voice.

A long time ago I played with MS sapi. I will try to put the relevant 
code here for you. My goal was to put the output speech into memory to 
be processed further.  I attached the generated speechlib_tlb unit. I 
think I used the fpc tool importtl to generate this unit. But its been a 
long time. The file is dated 2002.


Andrew Haines

    OleServer, ComObj, Speechlib_tlb, Windows, Variants,  ActiveX, ...

   SpeechVoice: ISpeechVoice;
   Voice: TSpVoice;
   Voices: ISpeechObjectTokens;
   ToSpeak: OleVariant;
   i: Integer;
   VoiceList: TStringList;
   Voice := TSpVoice.Create(self);
   CoCreateInstance(CLASS_SpVoice, nil, CLSCTX_ALL, IID_ISpeechVoice, 
   Voices := Voice.GetVoices('','');
   VoiceList := TStringList.Create;
   for i := 0 to Voices.Get_Count -1 do
   Voice.Voice := ISpeechObjectToken(Pointer(VoiceList.Objects[0])); // 
0 is the index of the desired voice.
   // VoiceList.Strings[x] is a text description of the voice

   ToSpeak := 'Hello MS SAPI';
   Voice.speak(ToSpeak, SVSFDefault);

   // cleanup
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SpeechLib_TLB.pas
Type: text/x-pascal
Size: 431830 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170411/cf7a159b/attachment.pas>

More information about the fpc-pascal mailing list