Voice to Code in CodeRush for Visual Studio

One of the more exciting features in this release is Voice to Code, which uses Visual Studio's IntelliSense to intelligently convert spoken words to code.

Voice to Code features are triggered with the right Ctrl key. Make sure you've set up voice features first.

To create a new simple expression inside source code, hold down the right Ctrl key and say the expression. Release the right Ctrl key when you have finished saying the expression.

For example, for qualified expressions like “a.b.c()”, you can omit the dots and parens and simply say “a b c”.

Also available:


Simple Expressions

In our initial release, Voice to Code supports the following simple expressions:
  • Qualified references to any symbol in scope (e.g., "myCustomer.DataPoints.Length")
  • nameof() and typeof() calls.
  • Method calls (e.g., "myCase.ToString()")
  • Linq expressions using method syntax (e.g, "myPoints.Select(x => x.Y).Max()")
  • Binary expressions (e.g, "myList.Count + myOtherList.Count" or "dataPoint.Time < DateTime.UtcNow) )
  • Numbers (e.g, "3.14159", "2024", "100", or "-9876543210.0123456789").

You can also reference symbols inside comments and strings, and add simple expressions to interpolated strings.

    Groundbreaking Next Generation Voice to Code Technology

    The Voice to Code engine works with Visual Studio's IntelliSense to evaluate a multiverse of phonetic interpretations, always trying to match the best code to the spoken phrase.
    As an example, consider the following simple expression that might appear inside an NUnit test case:
    Is.EqualTo(3)
    To get this expression, hold down the right Ctrl key inside Visual Studio (with the caret in a place where this expression could go) and simply say "is equal to three”.
    Release the right Ctrl key when you are done speaking. If the caret is inside an NUnit test case, the engine will find the "Is" class, then find its "EqualTo" method, and see that EqualTo() accepts a parameter (so it passes the "3" in as an argument because that makes the most sense in this context).
    Along the path to finding this solution, the engine evaluates other in-scope alternatives, possibly including in-scope variations that end in "23" (since the words "to three" sound exactly like "2 3").
    As a result, you rarely need to tell the engine where the dot qualifier goes - it simply solves that problem using IntelliSense. For example, if I want the expression "A().B().C().D()", I can say "A B C D". Of course, you can also explicitly point out where to place each dot delimiter by saying "dot" (which might be useful for resolving phonetic collisions).
    The Voice to Code engine knows if it is inserting a method, property, parameter, etc, and so it formats the code appropriately. That means method calls will always include parens, and Linq expressions will automatically include the “x => x” lambda declaration. For example, in the following code…
    if you want to return the highest y-value in a list of Points called "myPoints", hold down the right Ctrl key and simply say:
    "my points select y max"
    and you’ll get the following Linq expression:
    myPoints.Select(x => x.Y).Max()

    Let's take a closer look. In the code we want to create, we only said the important words (highlighted in yellow, below):

    Let’s consider another example. The following in-progress method wants to calculate the age in days that have passed since the specified DateTime parameter (named “time”).
    With the caret where we want our expression, hold down the right Ctrl key and say:
    date time UTC now minus time, total days”.
    (release the Ctrl key when you are done)
    The Voice to Code engine generates this:
    (DateTime.UtcNow - time).TotalDays
    Note that the engine realizes the subtracted difference between our two spoken DateTime instances is a TimeSpan (due to DateTime’s declared minus operator overload), and it knows the TotalDays property is available on TimeSpan instances (but not on the DateTime time instance). And so the engine concludes TotalDays must apply to the binary expression, and adds enclosing parentheses accordingly.
    Understanding binary expressions, method calls, and Linq expressions means you can omit the punctuation and pretty much say only the essential identifiers, operators, and numbers. CodeRush uses your spoken words along with IntelliSense to find the best fit.

    More on Numbers

    Numbers can be spoken a single digit at a time (e.g., "one two three" to get 123), in pairs (like “twenty twenty-four” to get “2024”), or using numeric words and multipliers (e.g., "one hundred and twenty three" to get 123, or “negative three thousand two hundred and fourteen” to get “-3214”). Use the word “point” to specify a decimal separator (e.g., "three point one four" to get 3.14).

    Enums

    The Voice to Code engine understands many places where enum elements are expected (e.g., parameters, assignments, equality comparisons, etc.), and as a result it's unlikely you'll ever need to explicitly say the Enum type name. For example, consider the following code:
    Now, with the caret where you want your expression, hold down the right Ctrl key and say
    "flavor equals chocolate".
    CodeRush will generate the following equality comparison expression:
    flavor == IceCreamFlavors.Chocolate
    Notice it correctly gets the name of the enum type ("IceCreamFlavors") without it ever having to be said.
    Again, highlighting the important parts of that expression that need to be said:


    Enum type names are generally never needed in the spoken phrase.

    Attributes
    To add an attribute, first enter the open square bracket into the code, and then press the right Ctrl key while saying the name of the attribute (and any arguments you want to pass).
    For example, consider the following code...

    if we want our ApiKey property to never appear in Visual Studio's debugger variable windows, with the caret inside the square brakets, press the right Ctrl key and say:

    "debugger browsable never"
    and you'll get this attribute:
    [DebuggerBrowsable(DebuggerBrowsableState.Never)]

    More Voice Features

    This release contains powerful features that support voice interaction in Visual Studio. Other posts documenting voice features in CodeRush:

    Limitations

    The engine works on simple expressions. This is a 1.0 release, and while we think there's groundbreaking power in what's shipping, there are some limitations. For starters, the technology is currently only available in C#. And the Voice to Code engine cannot recognize types that are not directly visible from the caret position -- using statements need to be in place to reference types in those namespaces.
    Additionally, the following structural code blocks are not supported (we recommend using CodeRush templates instead for all of these):
    • Type and member declarations.
    • Flow control elements (like for loops, try/finally, if/else, etc.).
    Here's some of what the Voice to Code technology does not yet support:
    • boolean literals (false, true)
    • null literal
    • assignment statements
    • != comparisons
    • string literals
    • is or as
    • scientific notation numeric literals
    • multiple arguments to a method call
    • named parameters
    • instance creation
    • Linq query syntax
    • semicolons placed after statements
    • property and array indexers
    • Boolean and binary operators like &&, ||, etc.
    • bit shifting operators like <<, >>, etc.
    We expect many of these limitations to be solved in subsequent releases.

    Free DevExpress Products - Get Your Copy Today

    The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.