Jump to content

Problem with Sapi 5 implementation


Fenzik
 Share

Recommended Posts

 Hello all"
I have curious problem with com object implementation of Sapi 5.1.
In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
But the Retrieved Voice object can speak the given text, so It exists and work.
Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)

So my question is> Is there some way to workaround or solve this issue?

What i tryed:

1. Typical use of Sapi.spvoice object:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
 
  $spvoice = ObjCreate("sapi.spvoice")
for $voice in $spvoice.getvoices()
  msgbox(0, "Voice", $voice.getdescription())
next

Func MyErrFunc()
$HexNumber = hex($oMyError.number, 8)
Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
SetError(1)
Endfunc


2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py

Thys code in Pascal should work, so i tryed to reproduce it in Autoit.

Pascal code just as example:

             SOTokens:=SpVoice.GetVoices('','');
             for i:=0 to SOTokens.Count-1 do
             try
                  SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
end

In Autoit I tryed it like this:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler

  $spvoice = ObjCreate("sapi.spvoice")
for $i = 0 to $spvoice.getvoices.count-1
$name = $spvoice.getvoices.item($i).getdescription
msgbox(0,"Voice", $name)
next

Func MyErrFunc()
$HexNumber = hex($oMyError.number, 8)
Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
SetError(1)
Endfunc

Both of this methods returning same Error ("Member not exists.").

Thanks a lot for help.
Znefyg

Link to comment
Share on other sites

Hello @Fenzik

Both examples working for my machine Windows 7 x64.

Check example below and tell me about error. 

Local $oSpvoice = ObjCreate("SApi.SPvoice")
If Not IsObj($oSpvoice) Then ConsoleWrite("+++ Error durning creation object." & @CRLF)

For $voice In $oSpvoice.GetVoices()
  ConsoleWrite($voice.GetDescription() & @CRLF)
Next

#Region COM Event handler.

Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; run function for verify COM exceptions.

Func MyErrFunc()
    Local $HexNumber = Hex($oMyError.number,8)
    ConsoleWrite("+++ We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "+++ err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "+++ err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "+++ err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "+++ err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "+++ err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "+++ err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "+++ err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "+++ err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
    SetError(1)
Endfunc

#EndRegion

My output:

; Output:
; Microsoft Anna - English (United States)
; >Exit code: 0    Time: 0.3973

 

Link to comment
Share on other sites

@Fenzik

The voices count has increased by 1 but not additional parameter Decription is given by KobaSpeech.

Take a look in this example.

Local $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; run function for verify COM exceptions.

; Type of speaker:
; 0 - Microsoft Anna - English (United States),
; 1 {on my PC} - KobaSpeech 3 Vocalizer Serena - English (Great Britain)
Local $iVoiceSpeaker = 1

Local $oSpvoice = ObjCreate("SApi.SPvoice")

; Get a new voice speaker
$oSpvoice.Voice() = $oSpvoice.GetVoices().Item($iVoiceSpeaker)

; Say something
$oSpvoice.Speak("Hello Fenzik! Im Serena. Let's works together.",0)


#Region COM Event handler.

Func MyErrFunc()
    Local $HexNumber = Hex($oMyError.number,8)
    ConsoleWrite("+++ We intercepted a COM Error !"       & @CRLF  & @CRLF & _
             "+++ err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "+++ err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "+++ err.number is: "         & @TAB & $HexNumber              & @CRLF & _
             "+++ err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "+++ err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "+++ err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "+++ err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "+++ err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
    SetError(1)
Endfunc

#EndRegion

 

Link to comment
Share on other sites

Ascer,

thank you for your Example.

It's totaly strange, that Koba voices don't provide information about their names by standart way, defined in Sapi SDK.

But in this case i have to know names of voices with i want to work before i list them by the object.

 

So my question is still:

Why other languages (Pascal, Python) can implement retrieving names by index (collection.item($n)) also in this strange case and Autoit Not.

Can this rely for example on given Data Type? I mean that other languages have the types exactly defined.

In Python Sapi Library (Url in First post) this problem is solved also only by fetching object items by their index and it works also for this Buggy Koba.

Koba voices also falls down when using any other methods, for example $voice.gettattribute("name").

So i want to know how way other programs can retrieve this informations (Name etc.) from Sapi object also in this strange cases.

As result i want to retrieve installed voices without knowing their names before only from the sapi object.

It have to work somehow, because developers of other programs using sapi (Balabolka, NVDA) solved this strange behaviour.

Link to comment
Share on other sites

Sorry, i don't have enough knowladge about it.

I can guess that problem is in Koba. He dont provide information about description or attribute in this some way as Microsoft Anna. You have to set it manually but it's an magic for me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...