Jump to content
Fenzik

Problem with Sapi 5 implementation

Recommended Posts

Fenzik

 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
Ascer

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
Fenzik

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
Ascer

@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
Fenzik

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
Ascer

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

  • Similar Content

    • genius257
      By genius257
      I've made a library, based on AutoItObject UDF with the goal of implementing getter and setter functionality and make it possible to define new object properties in as few steps as possible.
      Thank you to @trancexx for getting me on the right track, and all users in Hooking into the IDispatch interface for the code to get me going.
      If I've forgotten to add credit, please let me know
      Example:
      #include "AutoItObject_Internal.au3" $myCar = IDispatch() $myCar.make = 'Ford' $myCar.model = 'Mustang' $myCar.year = 1969 $myCar.__defineGetter('DisplayCar', DisplayCar) Func DisplayCar($oThis) Return 'A Beautiful ' & $oThis.parent.year & ' ' & $oThis.parent.make & ' ' & $oThis.parent.model EndFunc MsgBox(0, "", $myCar.DisplayCar) More examples: https://github.com/genius257/AutoItObject-Internal/tree/master/Examples
      Version: 2.0.0
      AutoItObject_Internal.au3
      Documentation
      Edit2 (19th March 2017):
      First of all, sorry about the lack of updates on this project. I always start too many projects and end up ignoring old projects, if I run into problems ^^'.
      So I've started moving my AutoIt scripts to GitHub. I will still post the most recent script version here.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I'm working on a little project of mines, and I was trying to use WMI Object.
      The question which I don't find an answer is: 
      Once I do the query with WMI Object, something like "SELECT * FROM Win32_LogonSession", instead of specify the field of the collection returned, ( i.e. $colItems.Caption ), can I loop though each property and each value of the property, writing so one row of code only?
      Hope my question was clear enough.
      Thanks in advance.

      Best Regards.
    • Bilgus
      By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version : 3.3.14.5
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      UDF:
      Test Script:
       
    • Bilgus
      By Bilgus
      I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt
      Turns out it was pretty easy.
      A Few Notes:
      CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.
      The Object must have IDispatch exposed (ITypeInfo is derivative)
      Its Just a proof of concept Run with it but don't carry scissors
      ITypeInfoCOM.au3
      ITypeInfoTest.au3
       
      Output IWebBrowserApp
       
      Output ObjCreate(MediaPlayer.MediaPlayer.1)
       
    • Bilgus
      By Bilgus
       IGroupPolicyObject interface
      ;;IGroupPolicyObject #RequireAdmin #include-once #include <WinAPIConstants.au3> ; $S_OK #include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}" Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}" Global Const $dtag_IGroupPolicyObject = _ "New hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name. "OpenDSGPO hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information. "OpenLocalMachineGPO hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information. "OpenRemoteMachineGPO hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information. "Save hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO. "Delete hresult();" & _ ; Deletes the GPO. "GetName hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO. "GetDisplayName hResult(wstr;int);" & _ ; Retrieves the display name for the GPO. "SetDisplayName hresult(wstr);" & _ ; Sets the display name for the GPO. "GetPath hResult(wstr;int);" & _ ; Retrieves the path to the GPO. "GetDSPath hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section. "GetFileSysPath hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section. "GetRegistryKey hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section. "GetOptions hResult(dword*);" & _ ; Retrieves the options for the GPO. "SetOptions hresult(dword;dword);" & _ ; Sets the options for the GPO. "GetType hResult(dword*);" & _ ; Retrieves type information for the GPO being edited. "GetMachineName hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO. "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO. Test() Func Test() Local $iResult Local $oIGroupPolicy Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"] $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject) While True If Not IsObj($oIGroupPolicy) Then ConsoleWrite("Failed To Retrieve Interface") $iResult = $E_NOINTERFACE ExitLoop Else ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF) EndIf Local $sLoc, $sPath, $sName, $iType $tKey = DllStructCreate("handle hKey") $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY)) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetName($sName, 65535) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sLoc & " : " & $sName & @CRLF) $iResult = $oIGroupPolicy.GetPath($sPath, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sPath & @CRLF) $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF) $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey)) If $iResult <> $S_OK Then ExitLoop ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF) ExitLoop WEnd Return SetError($iResult, 0, ($iResult = $S_OK)) EndFunc ;==>Test Note: Not well tested..
×