This is for having VC to execute commands when you can't get it to understand a command phrase. Kind of creates a second level of confidence, but with confirmation required.
Pre-reqs:
1-Python plugin enabled
2-Put this function inside an existing python script that you may be already using. If you still don't have any python script being loaded on the startup of VC, then you will need to create a new python script and set it to start with VC. This is beyond the scope of this thread.
3-Enable prefix mode. This is actually not 100% needed, but since I'm using prefix mode, my command has been designed to work on prefix mode. If you don't want to use prefix mode, please edit the IF logic on the command "Low confidence - 1st step".
More about your need for this (or not):
There are many times I say a command and it is not executed because the confidence was too low. This usually happens because of background noise, like people talking, kids playing or high volume in the TV.
So I built this command so I can make VC to execute commands even if the confidence is lower than the one that you set in Options.
If you say the same command phrase two times (you can adjust how many times) and the confidence in these two times are lower than the confidence you set in VC options, the script will tell you that it is guessing you are requesting such command and then ask for a confirmation.
Both the minimum confidence and the number of repeated times can be set in the script (variables confidence_threshold and repeated_times). These variables must be adjusted as to avoid false positives.
If you confirm the almost understood command shall be executed, then it is executed.
Not sure this is the best way to do it, but it's the way I found to be better.
python script (place in a python script that you will call at VC startup or create a new one that will be called at startup)
#below is part of main program (not a function), but has been put here to make it easier to understand what it refers to.
#it is run only at startup.
global phrase_previous_almost
phrase_previous_almost=""
global repeated_times
repeated_times=0
def almost_understood(phrase_almost_fnct="", confidence_pct_fnct=0):
global repeated_times
global repeated_threshold
global phrase_almost
global phrase_previous_almost
phrase_almost=phrase_almost_fnct
global confidence_pct
confidence_threshold=30 #minimum confidence required so the spoken phrase is not ignored
repeated_threshold=1 #minimum times the same phrase should be repeated and almost understood so VC asks if the command should be executed.
confidence_pct=num(confidence_pct_fnct)
print "repeated_times"
print repeated_times
print "phrase_almost"
print phrase_almost
print "phrase_previous_almost"
print phrase_previous_almost
if confidence_pct>=confidence_threshold:
print "confidence_pct>=confidence_threshold"
if phrase_previous_almost==phrase_almost:
repeated_times=repeated_times+1
print "phrase_previous_almost==phrase_almost"
print "repeated_times"
print repeated_times
if repeated_times>=repeated_threshold:
print "repeated_times>=repeated_threshold will return 1"
#here it means we said have repeated the same phrase 2 times with a confidence lower than required confidence,
#but higher than our minimum tolerance threshold.
#Then we will return a good value.
repeated_times=0
phrase_previous_almost=""
return 1
else:
print "phrase_previous_almost!=phrase_almost will reset counter and return 0"
repeated_times=0
phrase_previous_almost=phrase_almost
else:
print "confidence_pct<confidence_threshold will reset the counter and return 0"
repeated_times=0
phrase_previous_almost=""
print "repeated_times"
print repeated_times
print "phrase_almost"
print phrase_almost
print "phrase_previous_almost"
print phrase_previous_almost
return 0
def num(s):
try:
return int(s)
except ValueError:
try:
return float(s)
except ValueError:
return float(s.replace(",","."))
These are the required command groups in VC.
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<commandGroup open="True" name="Low Confidence" enabled="True" prefix="" priority="0" requiredProcess="" description="">
<command id="661" name="Prefix Active" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<if ifBlockDisabled="False" ifNot="False">
<ifType>(A)==(B)</ifType>
<ifParams>{LastEvent}&&VC.Prefix.End</ifParams>
<then>
<action>
<cmdType>Results.SetVar</cmdType>
<params>
<param>prefixactive</param>
<param>0</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
</then>
<else>
<action>
<cmdType>Results.SetVar</cmdType>
<params>
<param>prefixactive</param>
<param>1</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
</else>
</if>
<event>VC.Prefix.End</event>
<event>VC.Prefix.Start</event>
</command>
<command id="769" name="Low confidence - 1st step" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<if ifBlockDisabled="False" ifNot="False">
<ifType>(A)==(B)</ifType>
<ifParams>{Var.prefixactive}&&1</ifParams>
<then>
<action>
<cmdType>PY.ExecString</cmdType>
<params>
<param>result=almost_understood("{1}","{2}")</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
</then>
<else />
</if>
<if ifBlockDisabled="False" ifNot="False">
<ifType>(A)==(B)</ifType>
<ifParams>{LastResult}&&1</ifParams>
<then>
<action>
<cmdType>VC.TriggerEvent</cmdType>
<params>
<param>2nd.step.VC.Reco.TooLow</param>
<param>{1}</param>
<param>{2}</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
</then>
<else />
</if>
<event>VC.Reco.TooLow</event>
</command>
<command id="752" name="Low confidence - 2nd step" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>TTS.SpeakSync</cmdType>
<params>
<param>I think I heard you asking this: {1}. Can I go ahead? You can say: yes please</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Results.SetVar</cmdType>
<params>
<param>lowconfidencecmd</param>
<param>{1}</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Group.Disable</cmdType>
<params>
<param>Low Confidence</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Group.Enable</cmdType>
<params>
<param>Confirmar low confidence</param>
<param>30</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>VC.TriggerEvent</cmdType>
<params>
<param>EnableCustomConfirmation</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>VC.TellVox</cmdType>
<params>
<param>Confirma o comando</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<event>2nd.step.VC.Reco.TooLow</event>
</command>
</commandGroup>
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<commandGroup open="True" name="Confirmar low confidence" enabled="False" prefix="" priority="0" requiredProcess="" description="">
<command id="685" name="Confirma o comando?" enabled="true" alwaysOn="False" confirm="True" requiredConfidence="60" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>VC.TellVox</cmdType>
<params>
<param>{Var.lowconfidencecmd}</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Group.Disable</cmdType>
<params>
<param>Confirmar low confidence</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Group.Enable</cmdType>
<params>
<param>Low Confidence</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<phrase>Confirma o comando</phrase>
</command>
<command id="612" name="Reenable Low Confidence" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>Group.Enable</cmdType>
<params>
<param>Low Confidence</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>Group.Disable</cmdType>
<params>
<param>Confirmar low confidence</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<event>*.Confirma o comando?</event>
</command>
</commandGroup>
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<commandGroup open="True" name="Custom confirmation" enabled="False" prefix="" priority="0" requiredProcess="" description="">
<command id="712" name="comando de confirmação" enabled="true" alwaysOn="True" confirm="False" requiredConfidence="80" loop="False" loopDelay="0" loopMax="0" description="">
<action>
<cmdType>VC.ConfirmYes</cmdType>
<params />
<cmdRepeat>1</cmdRepeat>
</action>
<action>
<cmdType>OSD.AddText</cmdType>
<params>
<param>>Confirmado!</param>
</params>
<cmdRepeat>1</cmdRepeat>
</action>
<phrase>yes please</phrase>
</command>
</commandGroup>
Last edit to attach the final version as per conversation below. It's working now as of today July/9/2015.