Author Topic: Passing a spoken integer into a C#Script  (Read 5621 times)

Kingoftime

  • Guest
Passing a spoken integer into a C#Script
« on: May 04, 2017, 09:16:50 PM »
I am new to using this program in more depth and stuck on this issue.

I want to be able to say. "Pass number ###"
Then VA will take ### and pass it into the C# script where it will do some math to it.

Then I would like VA to Speak the new number.

Any help on this would be much appreciated!

Thank you!

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4778
  • RTFM
Re: Passing a spoken integer into a C#Script
« Reply #1 on: May 04, 2017, 09:47:32 PM »
Show us what you have already(including the C# inline function). That'll allow a more accurate answer.

Kingoftime

  • Guest
Re: Passing a spoken integer into a C#Script
« Reply #2 on: May 04, 2017, 09:51:33 PM »
Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
            int input = Convert.ToInt32(VA.ParseTokens("Input")) ;///pass value into here
            double dbl_output = 3;
            int int_output = 0;

            if (input > 900){
                   dbl_output = Math.Round((input * -1.11) + 2230.79);
                    }else{
                   dbl_output = Math.Round((input * -0.46) + 1610.51);
                }
            int_output = Convert.ToInt32(dbl_output);
            VA.SetInt("Output", int_output);
}
}
« Last Edit: May 05, 2017, 09:36:00 AM by Kingoftime »

Kingoftime

  • Guest
Re: Passing a spoken integer into a C#Script
« Reply #3 on: May 05, 2017, 09:38:13 AM »




Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

public class VAInline
{
public void main()
{
            int input = Convert.ToInt32(VA.ParseTokens("Input")) ;///pass value into here
            double dbl_output = 3;
            int int_output = 0;

            if (input > 900){
                   dbl_output = Math.Round((input * -1.11) + 2230.79);
                    }else{
                   dbl_output = Math.Round((input * -0.46) + 1610.51);
                }
            int_output = Convert.ToInt32(dbl_output);
            VA.SetInt("Output", int_output);
}
}

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Passing a spoken integer into a C#Script
« Reply #4 on: May 05, 2017, 09:49:32 AM »
I'm definitely no wizard programmer, but based on your example I think you're looking to round to an integer value. Does it need to be done via C#? If not here are some other options:

Non-Inline Function:
When I say: Pass Number*
Code: [Select]
Set decimal [input] value to the converted value of {TXTNUM:"{LASTSPOKENCMD}"}
Begin Decimal Compare : [input] Is Greater Than 900
    Set decimal [output] value to the converted value of {EXP:{DEC:input}*(-1.11)+2230.79} (round to 0 decimal places)
Else
    Set decimal [output] value to the converted value of {EXP:{DEC:input}*(-0.46)+1610.51} (round to 0 decimal places)
End Condition
Write '[Blue] input = {DEC:input}; output = {DEC:output}' to log
Say, 'output is {DEC:output}'  (and wait until it completes)

Via VB.net inline function:
When I say: Pass Number*
Code: [Select]
Set decimal [input] value to the converted value of {TXTNUM:"{LASTSPOKENCMD}"}
Inline VB Function: , wait until execution finishes
Write '[Blue] input = {DEC:input}; output = {DEC:output}' to log
Say, 'output is {DEC:output}'  (and wait until it completes)
and for the VB Inline...
Code: [Select]
Referenced Assemblies = System.dll;System.Core.dll;System.Data.dll;System.Data.DataSetExtensions.dll;System.Deployment.dll;System.Drawing.dll;System.Net.Http.dll;System.Windows.Forms.dll;System.Xml.dll;System.Xml.Linq.dll;mscorlib.dlland
Code: [Select]
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Drawing
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.Linq
Imports System.Xml.Linq
Imports System.Threading.Tasks

Public Class VAInline
Public Sub Main()
           
            Dim myInput, myOutput As Decimal
            myInput = VA.GetDecimal("input")

            If myInput<900 Then
                myOutput = Math.Round((myInput*-1.11)+2230.79)
            Else
                myOutput = Math.Round((myInput*-0.46)+1610.51)
            End If
           
            VA.SetDecimal("output", myOutput)
           
End Sub
End Class

Unfortunately I couldn't get C# code to properly compile (I'm a total noob in general when it comes to C# and VB), so I'm also interested to see how this should work (though upon looking at your code I think I messed up the conversion of data types).

Kingoftime

  • Guest
Re: Passing a spoken integer into a C#Script
« Reply #5 on: May 05, 2017, 12:28:20 PM »
It doesn't need to be done in C# im just trying to get this figured out really.

All I want is to be able to say "Do math on this number ### "

Then it takes the number ### and drops it into an equation, calculates, then speaks the answer back to me.

It feels like it should be an easy task but I think I'm over complicating it...

Exergist

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 405
  • Ride the lightning
Re: Passing a spoken integer into a C#Script
« Reply #6 on: May 05, 2017, 01:30:13 PM »
In that case it seems like this would take care of what you need:
Quote
Non-Inline Function:
When I say: Pass Number*
Code: [Select]
Set decimal [input] value to the converted value of {TXTNUM:"{LASTSPOKENCMD}"}
Begin Decimal Compare : [input] Is Greater Than 900
    Set decimal [output] value to the converted value of {EXP:{DEC:input}*(-1.11)+2230.79} (round to 0 decimal places)
Else
    Set decimal [output] value to the converted value of {EXP:{DEC:input}*(-0.46)+1610.51} (round to 0 decimal places)
End Condition
Write '[Blue] input = {DEC:input}; output = {DEC:output}' to log
Say, 'output is {DEC:output}'  (and wait until it completes)
You will probably need to make sure your "Command Weight" setting (page 87 of the help document) is not too high otherwise you may not get VA to properly recognize the numbers. Also keep in mind that you can do all kinds of operations (math and text) with the {EXP:} token (see page 121 of the help document).

Depending on whether you really need to be able to provide ANY number as opposed to a set of numbers, I'd say you have these options:
  • You can leverage a wildcard When I say like I've demonstrated above, so using your example the command would be executed by: Do math on this number* which will work to recognize any number. Though I believe there may be some issues recognizing integers (saying "10" vs "10.0") because VA may interpret the integer as TEXT instead of a number, which makes the {TXTNUM:} not function properly.
  • Employ a numeric range (see page 17 of the help document) if the amount of possible spoken numbers is relatively small and can be represented by integers. So if you're expecting to say "10," "20," or "30" then Do math on this number [1..3,10] would do math on 10, 20, or 30 (depending on what you say of course). The accuracy here will also tend to be much higher since VA is only listening for 3 numbers after the Do math on this number instead of being forced to listen for ANY number. Even allowing for a numeric range that contains 100 numbers will perform better than the wildcard scenario (in my experience).

Kingoftime

  • Guest
Re: Passing a spoken integer into a C#Script
« Reply #7 on: May 05, 2017, 02:15:54 PM »
I need to be able to pass any integer between 50-1230. So I don't really want to provide a case for everyone.

Rhaedas

  • Jr. Member
  • **
  • Posts: 72
Re: Passing a spoken integer into a C#Script
« Reply #8 on: May 05, 2017, 04:35:45 PM »
Break the problem down. Make sure that the code is getting what you think it's getting. You could put in a test code that takes in the input from VA and then spits it back out the VA into the buffer or saying it. If the number you say is getting through that, then you know it's something in the rest of the code that's wrong, but you have to make sure your input is good to begin with. Otherwise you're beating yourself up over a garbage in, garbage out problem.

Kingoftime

  • Guest
Re: Passing a spoken integer into a C#Script
« Reply #9 on: May 05, 2017, 05:40:41 PM »
I think all my code is good except for the input. I can put dummy values hardcoded in and I get good results. So i'm just stuck on actually getting the Number verbally in the system.

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4778
  • RTFM
Re: Passing a spoken integer into a C#Script
« Reply #10 on: May 05, 2017, 06:11:41 PM »
i'm just stuck on actually getting the Number verbally in the system.
There are two main options, one already presented:
When I say: Pass Number*
This uses a wildcard, meaning only one command phrase is generated, which minimizes profile loadtime, however recognition relies on dictation(I.E. the speech engine can't match what you say to a pre-determined phrase, so it has to "guess"). You'll want to try it and determine whether it's accurate enough for you.

Use the following action to get the data into VoiceAttack:
Code: [Select]
Set integer [input] value to the converted value of {TXTNUM:"{CMD}"}


The alternative is to generate phrase variations for all possible numbers:
Pass number [50..1230]
Same action applies to get the data into VoiceAttack.

This will increase the profile loadtime, as it'll generate 1180 phrases, but it should be more accurate.