Author Topic: VC.GetOption  (Read 5571 times)

0 Members and 1 Guest are viewing this topic.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
VC.GetOption
« on: July 30, 2014, 09:04:35 PM »
 By any chance there is undocumented VC.GetOption command?  ::hmm ::hmm ::hmm

I am doing it with 2 commands, but it would be much nicer VC.GetOption

File.Read  options.xml
Results.RegEx Option\sname="PrefixString"\svalue="(.*)"
« Last Edit: July 30, 2014, 09:18:51 PM by Haddood »
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #1 on: July 31, 2014, 10:15:55 AM »
The way you are doing it is fine.  I don't see a big benefit to making an action to do the same thing.  It would not be noticeably faster.

Keep in mind that you are only reading the option as stored in the xml which may not be the same as the options that might have been temporarily overridden.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: VC.GetOption
« Reply #2 on: July 31, 2014, 02:32:47 PM »
Keep in mind that you are only reading the option as stored in the xml which may not be the same as the options that might have been temporarily overridden.

That is exactly why it is needed  8) 8)
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #3 on: July 31, 2014, 03:17:36 PM »
When is your birthday?  ;)

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: VC.GetOption
« Reply #4 on: July 31, 2014, 04:08:04 PM »
When is your birthday?  ;)

I celebrate it every month   :biglaugh :biglaugh :biglaugh

but if you are serious about a birthday gift, I would love to have an event when a command recognized with the phrase and confidence as payloads  8) 8) 8)
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #5 on: July 31, 2014, 04:48:26 PM »
OK, I guess you will get a birthday and a Christmas present then.

Or a {insertYourPreferredChristmasAlternativeHere} present if you don't celebrate Christmas...   :D

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #6 on: July 31, 2014, 05:14:11 PM »
OK.  Here is your OSD solution.  Use this python code.  Auto-load it when VC starts.  Problem solved.

Code: [Select]
from System.Collections.Generic import *

def osdEvent(osdInfo):   
    strText = unicode(osdInfo.speechText)   
    strCommandName = unicode(osdInfo.commandName)
    strGroup = unicode(osdInfo.groupName)
    strConfidence= str(osdInfo.confidence)
    strPass = str(osdInfo.confidencePassed)   
    strDoingCommand=str(osdInfo.doingCommand)   
    vc.triggerEvent("VC.Reco", List[str]([strText, strCommandName, strGroup, strConfidence, strPass, strDoingCommand]))

vc.OnOSD -= osdEvent
vc.OnOSD += osdEvent

Note that this code will generate an event any time speech is recognized, whether it is executed or not.  If you want you can use an if statement to make it only execute if (osdInfo.confidencePassed==false) or whatever.  You could also change the event name to include information from one of the variables to get "VC.Reco.True" or "VC.Reco.False" or "VC.Reco.GroupName" etc.

If there are variables in there that you don't need you can remove them to make it a bit more efficient.

Note the difference between osdInfo.confidencePassed and osdInfo.doingCommand.  You may pass the confidence test, but still not execute the command for various reasons, like being in standby, or there being too many alternates.

Note that the object does not contain any information about prefix, other than the actual speechText.

[Code box updated 14-Oct-2015 to address character encoding problem. See thread discussion here: http://voxcommando.com/forum/index.php?topic=1689.msg20320#msg20320]
« Last Edit: October 14, 2015, 07:50:35 AM by nime5ter »

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: VC.GetOption
« Reply #7 on: July 31, 2014, 06:48:47 PM »
first let me say  ::bow ::bow


OK, I guess you will get a birthday and a Christmas present then.

Or a {insertYourPreferredChristmasAlternativeHere} present if you don't celebrate Christmas...   :D

if it comes to VC features as presents I will celebrate even the undiscovered Amazonian tribes special days  :biglaugh :biglaugh
When Voice command gets tough, use hand gestures

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #8 on: July 31, 2014, 07:10:53 PM »
hmmm, even stretch-your-lip-up-over-the-top-of-your-head day?

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: VC.GetOption
« Reply #9 on: July 31, 2014, 08:27:51 PM »
hmmm, even stretch-your-lip-up-over-the-top-of-your-head day?

this one I will pass cause VC will find hard time understanding me !!!
When Voice command gets tough, use hand gestures

fishware

  • Jr. Member
  • **
  • Posts: 44
  • Karma: 1
    • View Profile
Re: VC.GetOption
« Reply #10 on: October 13, 2015, 04:07:36 PM »
Hello everyone.

I want to use the script like in

http://voxcommando.com/forum/index.php?topic=1845.0

but it comes up with the following error:

Code: [Select]
System.Text.DecoderFallbackException: Die Bytes [F6] im Index 0 können nicht von der angegebenen Codepage in Unicode übersetzt werden.
   bei System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
   bei System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
   bei IronPython.Runtime.PythonAsciiEncoding.GetCharCount(Byte[] bytes, Int32 index, Int32 count)
   bei System.Text.Encoding.GetChars(Byte[] bytes, Int32 index, Int32 count)
   bei System.Text.Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
   bei IronPython.Runtime.Operations.StringOps.DoDecode(CodeContext context, String s, String errors, String encoding, Encoding e)
   bei IronPython.Runtime.Operations.StringOps.RawDecode(CodeContext context, String s, Object encodingType, String errors)
   bei IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, Object string, String encoding, String errors)
   bei IronPython.Runtime.Operations.StringOps.CheckAsciiString(CodeContext context, String s)
   bei IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, String object)
   bei Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   bei System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   bei Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   bei IronPython.Compiler.PythonCallTargets.OriginalCallTarget1(PythonFunction function, Object arg0)
   bei System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   bei _Scripting_(Object[] , osdInfo )
   bei PluginInterface.doOsdEvent.Invoke(osdInfo oInfo)
   bei VoxCommando.PluginServices.fireOsdEvent(osdInfo oInfo)
   bei eval_f.eval_ᜀ(Object A_0, SpeechRecognizedEventArgs A_1)
13.10.2015 21:03:43 424 [error] unexpected error:
System.Text.DecoderFallbackException: Die Bytes [F6] im Index 0 können nicht von der angegebenen Codepage in Unicode übersetzt werden.
   bei System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)
   bei System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)
   bei IronPython.Runtime.PythonAsciiEncoding.GetCharCount(Byte[] bytes, Int32 index, Int32 count)
   bei System.Text.Encoding.GetChars(Byte[] bytes, Int32 index, Int32 count)
   bei System.Text.Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
   bei IronPython.Runtime.Operations.StringOps.DoDecode(CodeContext context, String s, String errors, String encoding, Encoding e)
   bei IronPython.Runtime.Operations.StringOps.RawDecode(CodeContext context, String s, Object encodingType, String errors)
   bei IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, Object string, String encoding, String errors)
   bei IronPython.Runtime.Operations.StringOps.CheckAsciiString(CodeContext context, String s)
   bei IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, String object)
   bei Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   bei System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   bei Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   bei Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   bei IronPython.Compiler.PythonCallTargets.OriginalCallTarget1(PythonFunction function, Object arg0)
   bei System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   bei _Scripting_(Object[] , osdInfo )
   bei PluginInterface.doOsdEvent.Invoke(osdInfo oInfo)
   bei VoxCommando.PluginServices.fireOsdEvent(osdInfo oInfo)
   bei eval_f.eval_ᜀ(Object A_0, SpeechRecognizedEventArgs A_1)

I use Windows 10 Prof 64bit

All other things works fine

Thank you in advanced

Chris



« Last Edit: October 13, 2015, 04:11:24 PM by jitterjames »

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #11 on: October 13, 2015, 04:13:17 PM »
Please post the code you are using that generates that error.  It if it python please post the python code and if it is a command please post the xml.  It is really not clear from the link you provided what you are actually doing.

fishware

  • Jr. Member
  • **
  • Posts: 44
  • Karma: 1
    • View Profile
Re: VC.GetOption
« Reply #12 on: October 13, 2015, 04:22:11 PM »
Hey James,

I use your python code from this topic

http://voxcommando.com/forum/index.php?topic=1689.msg14686#msg14686

So the used Pythoncode is

Code: [Select]

from System.Collections.Generic import *

def osdEvent(osdInfo):   
    strText = str(osdInfo.speechText)   
    strCommandName = str(osdInfo.commandName)
    strGroup = str(osdInfo.groupName)
    strConfidence= str(osdInfo.confidence)
    strPass = str(osdInfo.confidencePassed)   
    strDoingCommand=str(osdInfo.doingCommand)   
    vc.triggerEvent("VC.Reco", List[str]([strText, strCommandName, strGroup, strConfidence, strPass, strDoingCommand]))

vc.OnOSD -= osdEvent
vc.OnOSD += osdEvent

I Hope it helps

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: VC.GetOption
« Reply #13 on: October 13, 2015, 08:47:32 PM »
nime5ter figured out that it was having trouble dealing with accented characters in either your command name or phrases.  The str() function is not able to cope with them.

Using the unicode() function instead seems to solve the problem, at least in my simple tests.

Try this python code:
Code: [Select]
from System.Collections.Generic import *

def osdEvent(osdInfo):   
    strText = unicode(osdInfo.speechText)   
    strCommandName = unicode(osdInfo.commandName)
    strGroup = unicode(osdInfo.groupName)
    strConfidence= str(osdInfo.confidence)
    strPass = str(osdInfo.confidencePassed)   
    strDoingCommand=str(osdInfo.doingCommand)   
    vc.triggerEvent("VC.Reco", List[str]([strText, strCommandName, strGroup, strConfidence, strPass, strDoingCommand]))

vc.OnOSD -= osdEvent
vc.OnOSD += osdEvent

fishware

  • Jr. Member
  • **
  • Posts: 44
  • Karma: 1
    • View Profile
Re: VC.GetOption
« Reply #14 on: October 14, 2015, 05:34:08 PM »
 :yay :yay

Thank you Boys. It works great. Another step to my perfect Voxcontrolled home.

Kind regards Chris