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.
    • xiantez
      By xiantez
      This script used to work on an older version of AutoIT. Currently I am running AutoIT v3.3.14.5 and it's failing.
      Func PublicIP() ;Post public facing IP address Local $url = 'https://www.google.com/search?client=opera&q=what+is+my+ip&sourceid=opera&ie=UTF-8&oe=UTF-8' Local $getIPaddress = BinaryToString(InetRead($url)) Local $sStart = 'clamp:2">' Local $sEnd = '</div>' Local $ipaddress = _StringBetween($getIPaddress, $sStart, $sEnd For $i In $ipaddress MsgBox(0, 'External IP', "Your public IP address is " & $i) Next EndFunc ;==>PublicIP The console output shows:
      "C:\Users\user\Documents\AutoIT\Scripts\WSI Tools.au3" (197) : ==> Variable must be of type "Object".: For $i In $ipaddress For $i In $ipaddress^ ERROR ->14:12:16 AutoIt3.exe ended.rc:1 +>14:12:16 AutoIt3Wrapper Finished. >Exit code: 1 Time: 9.811
    • tuffgong
      By tuffgong
      Good morning. I have a system I am trying to automate that works like this: user fills a column in an Excel spreadsheet with values they would like printed and saves it to a folder on their desktop, they start the script and it formats their data into a text file (adding a prefix) and sends the text file as a .bch file where it needs to go. This is working:
      #include <Array.au3> #include <Excel.au3> #include <File.au3> #include <MsgBoxConstants.au3> Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) barcodePrint() Func barcodePrint() $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) FileOpen($sFilename, $FO_OVERWRITE) ;Global $oWorkbook = _Excel_BookAttach($oExcel) Global $sSTCArray = _Excel_RangeRead($Read) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, "!StaticShelving1x3_ZPL," & $sSTCArray[$i]) Next _Excel_Close($oExcel) FileMove($sFilename, "***file path***\print.bch") EndFunc However, it only works if the user first formats the spreadsheet to text. I want to automate that. From what I have read it appears AutoIt does not like formatting cells that already have values. True? Can I pull the values from an un-formatted (default GENERAL format) spreadsheet and go straight to my text file? I have also considered opening a second spreadsheet, formatting it, and copying the values over. Like this:
        
      Global $sPrefix Global $oPath Global $sSTCArray Global $sFilename = @DesktopDir & "\Labels\print.txt" Global $sWorkbook = @DesktopDir & "\Labels\Labels.xlsx" Global $oExcel = _Excel_Open(False,False,False,False,True) Global $aArray Global $bExcel _Excel_BookNew($bExcel) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $aArray = IniReadSection("***File path***\barcode.ini", "stc/rvt/mgm") $sPrefix = $aArray[1][1] $oPath = $aArray[2][1] barcodePrint() EndSwitch WEnd Func barcodePrint() $oWorkbook = _Excel_BookOpen($bExcel, @DesktopDir & "\Labels\print.xlsx") $oWorkbook.ActiveSheet.Columns("A").NumberFormat = "@" Local $Read = _Excel_BookOpen($oExcel, $sWorkbook, True, False, Default, Default, Default) $oCopy = _Excel_RangeRead($sWorkbook) _Excel_RangeWrite($oWorkbook, Default, $oCopy) FileOpen($sFilename, $FO_OVERWRITE) $sSTCArray = _Excel_RangeRead($Read,"Default","Default",3) ;_ArrayDisplay($sSTCArray) For $i = 0 to UBound($sSTCArray, 1) - 1 FileWriteLine($sFilename, $sPrefix & $sSTCArray[$i]) Next _Excel_Close($oExcel) ;FileMove($sFilename, $oPath) Exit EndFunc This does not like the formatting of $oWorkbook: "Variable must be of type 'Object'".  Do I need this second sheet? If so, how can I format it? Is there a better way to get the Excel values into a .txt file? Any ideas would be appreciated. Thanks!
    • marcoauto
      By marcoauto
      Ciao
      I would like to control an ATEM Video Mixer from autoit. I downloaded his SDK which is written in c ++ and I found the sequences to interface, but I was not able to convert the script to self.
      The instructions say to follow this sequence:
      and to connectTo with C++ is:
      string address = "192.168.1.240"; _BMDSwitcherConnectToFailure failureReason = 0; IBMDSwitcher switcher = null; var discovery = new CBMDSwitcherDiscovery(); discovery.ConnectTo(address, out switcher, out failureReason); From Blackmagic SDK:
      IBMDSwitcherDiscovery::ConnectTo method
      The ConnectTo method connects to the specified switcher and returns an IBMDSwitcher object interface for the switcher.
      Syntax HRESULT ConnectTo (string deviceAddress, IBMDSwitcher** switcherDevice, BMDSwitcherConnectToFailure* failReason); Parameters: deviceAddress in Network hostname or IP address of switcher to connect to. switcherDevice out IBMDSwitcher object interface for the connected switcher. failReason out Reason for connection failure as a BMDSwitcherConnectToFailure value. So, I have I tried these solutions but with non success:
      $DllName =@ScriptDir&"\BMDSwitcherAPI.dll" $result = DllCall($DllName, "none", "IBMDSwitcherDiscovery::ConnectTo" & @CRLF) ConsoleWrite("DLLCall Result: " & $result & @CRLF) and I have tried also create an Object (That I think is the best way solution):
      #include <MsgBoxConstants.au3> $oSwitcher=ObjCreate("IBMDSwitcher") If IsObj($oSwitcher) Then MsgBox(64, "", "Object $oSwitcher created successfully") EndIf $oAtem=ObjCreate("IBMDSwitcherDiscovery") If IsObj($oAtem) Then MsgBox(64, "", "Object $oAtem created successfully") EndIf $failureReason =ObjCreate("_BMDSwitcherConnectToFailure") If IsObj($failureReason) Then MsgBox(64, "", "Object $failureReason created successfully") EndIf $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler Global $errore,$oSwitcher1 $oAtem.ConnectTo("192.168.1.36",$oSwitcher,$failureReason); ; This is the custom error handler Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription & @CRLF & _ "Source is: " & $oMyError.source & @CRLF & _ "Description is: " & $oMyError.description & @CRLF & _ "Helpfile is: " & $oMyError.helpfile & @CRLF & _ "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _ "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _ "Scriptline is: " & $oMyError.scriptline) EndFunc ;==>MyErrFunc But the result is:
      We intercepted a COM Error !
      Number is: 000000A9
      Windescription is: Variable must be of type 'Object'.
      Source is: 
      Description is: 
      Helpfile is: 
      Helpcontext is: 
      Lastdllerror is: 0
      Scriptline is: 17
      The BMDSwitcherAPI.dll is registered in system. Can someone help me?
      Grazie
      Marco
    • 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 
      _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile  
      UDF:
      Test Script:
       
×