Jump to content
Sign in to follow this  
Fenzik

Problem with Sapi 5 implementation

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

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

Yeah! It works with "normal voices".:)

But when you install engine from the First post (can work as demo), my problem will appear.:)

Thx

Fenzik

Share this post


Link to post
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

 

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      hello autoit team
      please
      i tried to create a SPVoice object 
      when i create the object and tried to use this function SetAlertBoundary
      it gave me an error
      please where is the problem?
      here is the code
      local $o_Sapi_OBJ = ObjCreate("SAPI.SpVoice") if IsObj($o_Sapi_OBJ) then $o_Sapi_OBJ.SetAlertBoundary("SPEI_PHONEME") endIf note i got the function name from microsoft web site
       
      https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms719784(v=vs.85)
      i have windows10
    • By Colduction
      Hi AutoIt Programmers!

      I've seen a code that gives Name of Group by writing it's group's SID, but this one response very slower than Windows Command-Line WMIC
       
      Func _GetLocalGroupName($sSID = 'S-1-5-18') $objWMIService = ObjGet ("winmgmts:\\" & @ComputerName & "\root\cimv2") $colItems = $objWMIService.ExecQuery('SELECT Name FROM Win32_Group where SID="' & $sSID & '"') For $GroupNames in $colItems MsgBox (0,"",$GroupNames.Name) ExitLoop Next EndFunc I don't want call and use any third-party programs even CMD, i just want use from Windows API, netapi32.dll or AutoIt Functions (Standalone).
      Do you have any idea to improve speed/performance of this code? I'll happy of your comments
       
       
       
      ====================== SOLOUTION by @Subz ======================
       
    • By Surya
      Utter is simply a UDF created for the maximum utilization of SAPI (Speech Recognition API) in windows you can add your own words to be recognized by the computer you can set speed,picth and select the voice you want by speech synthesis included in windows.Utter can create a free grammar recognition engine as well as custom made grammar recognition engine suiting according to your need also it is flexible.The shutdown function of the UDF must be called before calling another one to destroy the current engine running when autoit closes the engine will also close many functionalities are included an update will be soon in future
      github: https://github.com/thesunRider/Utter
    • By Colduction
      Hello again, i have a code that changes username to favorite, my problem is how to use ObjEvent() function to catch errors, i've red Help File and Forum's Topics but i can't understand too much😐

      Here is a code (I've copied this codes from a user of AutoIt Forum):
       
      $sOldUser = "Administrator" $sNewUser = "Admin" $oUser = ObjGet("WinNT://" & @ComputerName & "/" & $sOldUser & ",user") $oComputer = ObjGet("WinNT://" & @ComputerName) $oNewUser = $oComputer.MoveHere($oUser.ADsPath, $sNewUser) Thanks for your care, I'm new to AutoIt and days should be passed with my coding and practicing to don't bother you :)❤
×
×
  • Create New...