Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-08

Can not set voice property of SpVoice

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Toru Takubo

Hello,

I am testing a text to speech program working on Windows SAPI, and I encountered a problem that I can not set the Voice property because "member not found".

Below is the code which describe the problem. It is originally from the freepascal wiki (http://wiki.freepascal.org/SAPI) and slightly modified. Setting the voice property in this code is meaningless, I know. It is just to reproduce the problem.

The SpVoice.Speak method itself works fine. I am working with fpc 3.0.0 on Windows 7 64bit. Any advice would be appreciated.

Regards,

Toru

_______________________________________________
program TestSAPI;
uses
   SysUtils, comobj;
var
   SavedCW: Word;
   SpVoice: Variant;
   Token: Variant;
begin
   SpVoice := CreateOleObject('SAPI.SpVoice');
   // Change FPU interrupt mask to avoid SIGFPE exceptions
   SavedCW := Get8087CW;
   try
     Set8087CW(SavedCW or $4);
     Token := SpVoice.Voice; //I can get a voice token.
     Writeln(Token.GetDescription); //The token actually works.
     try
       SpVoice.Voice := Token; //"member not found" exception here. I can't set it.
     except
       on E:Exception do begin
         Writeln(E.Message);
       end;
     end;
     SpVoice.Speak('hi', 0);
   finally
     // Restore FPU mask
     Set8087CW(SavedCW);
   end;
   Readln;
end.

Reply by email

Michael Van Canneyt
to Toru Takubo
Toru Takubo wrote 39 lines
Hello, I am testing a text to speech program working on Windows SAPI, and I encountered a problem that I can not set the Voice property because "member not found". Below is the code which describe the problem. It is originally from the freepascal wiki (http://wiki.freepascal.org/SAPI) and slightly modified. Setting the voice property in this code is meaningless, I know. It is just to reproduce the problem. The SpVoice.Speak method itself works fine. I am working with fpc 3.0.0 on Windows 7 64bit. Any advice would be appreciated. Regards, Toru _______________________________________________ program TestSAPI; uses SysUtils, comobj; var SavedCW: Word; SpVoice: Variant; Token: Variant; begin SpVoice := CreateOleObject('SAPI.SpVoice'); // Change FPU interrupt mask to avoid SIGFPE exceptions SavedCW := Get8087CW; try Set8087CW(SavedCW or $4); Token := SpVoice.Voice; //I can get a voice token. Writeln(Token.GetDescription); //The token actually works. try SpVoice.Voice := Token; //"member not found" exception here. I can't set it.

Did you try

   spVoice.SetVoice(Token);

?

Michael.

Reply by email

Toru Takubo
to Michael Van Canneyt
Michael Van Canneyt wrote 48 lines
On Tue, 23 Aug 2016, Toru Takubo wrote: > Hello, > > I am testing a text to speech program working on Windows SAPI, and I > encountered a problem that I can not set the Voice property because > "member not found". > > Below is the code which describe the problem. It is originally from > the freepascal wiki (http://wiki.freepascal.org/SAPI) and slightly > modified. Setting the voice property in this code is meaningless, > I know. It is just to reproduce the problem. > > The SpVoice.Speak method itself works fine. I am working with fpc > 3.0.0 on Windows 7 64bit. Any advice would be appreciated. > > Regards, > > Toru > > _______________________________________________ > program TestSAPI; > > uses > SysUtils, comobj; > var > SavedCW: Word; > SpVoice: Variant; > Token: Variant; > begin > SpVoice := CreateOleObject('SAPI.SpVoice'); > // Change FPU interrupt mask to avoid SIGFPE exceptions > SavedCW := Get8087CW; > try > Set8087CW(SavedCW or $4); > > Token := SpVoice.Voice; //I can get a voice token. > Writeln(Token.GetDescription); //The token actually works. > > try > SpVoice.Voice := Token; //"member not found" exception here. I can't set it. Did you try spVoice.SetVoice(Token);

I got another exception.

"Method 'SetVoice' is not supported by automation object"

Regards,
Toru

Reply by email

Michael Van Canneyt
to Toru Takubo
Toru Takubo wrote 56 lines
On 2016/08/23 16:22, Michael Van Canneyt wrote: > > > On Tue, 23 Aug 2016, Toru Takubo wrote: > >> Hello, >> >> I am testing a text to speech program working on Windows SAPI, and I >> encountered a problem that I can not set the Voice property because >> "member not found". >> >> Below is the code which describe the problem. It is originally from >> the freepascal wiki (http://wiki.freepascal.org/SAPI) and slightly >> modified. Setting the voice property in this code is meaningless, >> I know. It is just to reproduce the problem. >> >> The SpVoice.Speak method itself works fine. I am working with fpc >> 3.0.0 on Windows 7 64bit. Any advice would be appreciated. >> >> Regards, >> >> Toru >> >> _______________________________________________ >> program TestSAPI; >> >> uses >> SysUtils, comobj; >> var >> SavedCW: Word; >> SpVoice: Variant; >> Token: Variant; >> begin >> SpVoice := CreateOleObject('SAPI.SpVoice'); >> // Change FPU interrupt mask to avoid SIGFPE exceptions >> SavedCW := Get8087CW; >> try >> Set8087CW(SavedCW or $4); >> >> Token := SpVoice.Voice; //I can get a voice token. >> Writeln(Token.GetDescription); //The token actually works. >> >> try >> SpVoice.Voice := Token; //"member not found" exception here. I can't >> set it. > > Did you try > > spVoice.SetVoice(Token); > I got another exception. "Method 'SetVoice' is not supported by automation object"

Strange, because it is listed in the SAPI reference.

This is probably why you cannot set it: the property seems to be read-only.

Michael.

Reply by email

Toru Takubo
to Michael Van Canneyt
Michael Van Canneyt wrote 64 lines
On Tue, 23 Aug 2016, Toru Takubo wrote: > > > On 2016/08/23 16:22, Michael Van Canneyt wrote: >> >> >> On Tue, 23 Aug 2016, Toru Takubo wrote: >> >>> Hello, >>> >>> I am testing a text to speech program working on Windows SAPI, and I >>> encountered a problem that I can not set the Voice property because >>> "member not found". >>> >>> Below is the code which describe the problem. It is originally from >>> the freepascal wiki (http://wiki.freepascal.org/SAPI) and slightly >>> modified. Setting the voice property in this code is meaningless, >>> I know. It is just to reproduce the problem. >>> >>> The SpVoice.Speak method itself works fine. I am working with fpc >>> 3.0.0 on Windows 7 64bit. Any advice would be appreciated. >>> >>> Regards, >>> >>> Toru >>> >>> _______________________________________________ >>> program TestSAPI; >>> >>> uses >>> SysUtils, comobj; >>> var >>> SavedCW: Word; >>> SpVoice: Variant; >>> Token: Variant; >>> begin >>> SpVoice := CreateOleObject('SAPI.SpVoice'); >>> // Change FPU interrupt mask to avoid SIGFPE exceptions >>> SavedCW := Get8087CW; >>> try >>> Set8087CW(SavedCW or $4); >>> >>> Token := SpVoice.Voice; //I can get a voice token. >>> Writeln(Token.GetDescription); //The token actually works. >>> >>> try >>> SpVoice.Voice := Token; //"member not found" exception here. I can't set it. >> >> Did you try >> >> spVoice.SetVoice(Token); >> > > I got another exception. > > "Method 'SetVoice' is not supported by automation object" Strange, because it is listed in the SAPI reference. This is probably why you cannot set it: the property seems to be read-only.

I wrote a JScript (saved as tts.js) and it worked fine. _______________________________________________
var SpVoice = WScript.CreateObject("SAPI.SpVoice");

var Token = SpVoice.Voice;
WScript.Echo(Token.GetDescription());
SpVoice.Voice = Token;
SpVoice.Speak("hi");
_______________________________________________

I could even change voice with additional code.
Why my pascal code does not work as jscript does?

Regards,
Toru

Reply by email