[fpc-pascal] SpVoice.GetVoices returned exception class EOleSysError
Andrew Haines
andrewd207 at aol.com
Tue Apr 11 23:34:34 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 think I used the fpc tool importtl to generate
the Speechlib_tlb unit. But its been a long time now. I can email you
directly the file if you want.
Regards,
Andrew Haines
uses
OleServer, ComObj, Speechlib_tlb, Windows, Variants, ActiveX, ...
var
SpeechVoice: ISpeechVoice;
Voice: TSpVoice;
Voices: ISpeechObjectTokens;
ToSpeak: OleVariant;
i: Integer;
VoiceList: TStringList;
begin
CoInitialize(nil);
Voice := TSpVoice.Create(self);
CoCreateInstance(CLASS_SpVoice, nil, CLSCTX_ALL, IID_ISpeechVoice,
SpeechVoice);
Voice.ConnectTo(SpeechVoice);
Voices := Voice.GetVoices('','');
VoiceList := TStringList.Create;
for i := 0 to Voices.Get_Count -1 do
VoiceList.AddObject(Voices.Item(I).GetDescription(0),
TObject(Voices.Item(I)));
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
end;
More information about the fpc-pascal
mailing list