Voice Input Modes in CodeRush for Visual Studio

CodeRush versions 24.1.5 and up add dynamically selectable Input Modes to its Voice to Code technology, useful for dictating mixed-mode code expressions, such as code expressions that include string literals or undeclared identifiers.

Background

CodeRush's Voice to Code features include dedicated Input Modes selected automatically based on context. For example, if voice features are used inside a string literal, dictation mode is active and your spoken words (along with spaces, sentence capitalization, punctuation, etc.) will appear inside the string. A summary of the three primary input modes is summarized below:

User-activated Input Modes

Users can change the input mode while talking by pressing a modifier key (such as Alt or Shift), allowing a subset of the spoken words to be interpreted according to that newly activated input mode. Any words spoken while one or both of these modifier keys are held down will be interpreted with the specified alternate input mode.

For example, if the caret is inside a string and dictation mode is active, the user can hold down the Alt key to convert their spoken words to an interpolated string symbol/expression reference (see string dictation for more details). Or if the caret is inside an XML Documentation Comment, and dictation mode is active, the user can hold down the Alt key to reference a symbol (e.g., a parameter to the method, another member, or another class), and CodeRush will insert the appropriate <cref> or <paramref> tags for that symbol (see comment dictation for more details).

In both examples, simply hold a modifier key down while speaking the words that need the alternate interpretation.

New in this Release

CodeRush adds additional switchable input modes in this release, allowing you to create new identifiers (hold down the Alt key) and string literals (hold down the Shift key) in voice-to-code.

Specific examples of the new modes follow in the sections below.

Here's a summary of currently supported user-activated modes:

Shift Key for String Literals

If you need a string literal in your voice-to-code session, hold down the Shift key while talking.
For example, to adorn a unit test method with a new Category attribute for a category named "Core", you first position the caret inside square brackets ([]). This tells CodeRush you want to dictate an Attribute. Then hold down the right Ctrl key and say "Category Core", also holding down the Shift key while saying the word "Core". CodeRush will generate the following attribute with the string literal "Core" for your test case:
[Category("Core")]

For another example, consider the following code:

public Customer CreateCustomer(string name, int id) {
    return new Customer(name, id, DateTime.UtcNow);
}

public void CreateTestCustomers() {
    var testCustomer = ;
}

With the caret on line containing the incomplete assignment to testCustomer (before the semicolon), hold down the right Ctrl key to start the voice-to-code session, and say "Create Customer with John Smith and forty two", also holding down the Shift key while saying the words "John Smith". CodeRush will generate the following expression for the assignment that includes the string literal "John Smith"

public void CreateTestCustomers() {
    var testCustomer = CreateCustomer("John Smith", 42);
}

You can even create code like this entire line (e.g., declare the new variable initialized with a method call having a string literal as an argument) in a single voice-to-code session (more on this below).

Alt Key for New Identifiers

If you need to reference a yet-to-be-declared identifier, hold down the Alt key while speaking the words of the new identifier name. As an example, consider the following code:
void GetPercentOfTotal(double num1, double num2, double percent, out double answer) {  
}
To declare a new variable called totalSum, and assign it the sum of num1 and num2, just say "total sum gets num one plus num two" (hold down the Alt key while saying "total sum"). CodeRush will declare the totalSum variable and initialize it with the following code:
var totalSum = num1 + num2
Continuing the example in this method, on the next line you could say "temp answer gets total sum times percent" (holding down the Alt key while saying "temp answer") to generate this code:
var tempAnswer = totalSum * percent
Declaring new variables by voice also works with ref and out parameters. For example, consider the following code:
public bool TimeIsValid(string accountingPeriod) {

}
If the caret is inside the method and the spoken words are "date time try parse accounting period result" (and the Alt key is held down while speaking the word "result"), CodeRush will generate the following code, declaring a new variable named result as an out parameter, like this:
DateTime.TryParse(accountingPeriod, out var result)
If you want your undeclared identifier to be a method call, release the Alt key after you say the method name and follow it with the spoken keyword "with" along with any optional arguments you want to pass to the method. If the new method call will have no arguments you can end the spoken phrase with the word "with".

For example, with the caret inside the body of a method, you can say "initialize core engines with" (holding down the Alt key while saying "initialize core engines") to generate the following call to the specified undeclared method:

InitializeCoreEngines()

As another example, consider the following code:

void CertifyProficiency(string name, Guid id) {
    var student1 =  ; 
}

Inside the method before the semicolon, hold down the right Ctrl key to start a voice-to-code session, and say "create student with name and I.D.", holding down the Alt key while speaking the words "create student", CodeRush will create a new method call with the specified arguments, like this:

void CertifyProficiency(string name, Guid id) {
    var student1 = CreateStudent(name, id);
}

Note that the Alt key is only needed when referencing undeclared methods and variables in speech. To call existing methods, simply refer to them by name while speaking (with only the right Ctrl key down).

Using the New Modifiers Together

You can use the Alt and Shift modifiers in a single spoken phrase.
For example, if the spoken words are "display message gets hello world", and you hold down the Alt key while saying "display message", and later hold the Shift key down while saying "hello world", CodeRush declares a new variable named displayMessage, initializing it to the literal string "hello world." like this:
var displayMessage = "hello world."

For a more sophisticated example, consider the following code:

public Customer CreateCustomer(string name, int id) {
    return new Customer(name, id, DateTime.UtcNow);
}

public void CreateTestCustomers() {
    ; 
}

With the caret before the semicolon in the CreateTestCustomers method, try saying "test customer one gets create customer with Jackie Smith and one seventy two", holding down the Alt key while saying "test customer one", and later hold the Shift key down while saying "Jackie Smith ", CodeRush will generate the following code:

var testCustomerOne = CreateCustomer("Jackie Smith", 172)

In this example CodeRush declares a new variable (testCustomerOne), creates the assignment statement (from the word "gets") and passes in the string literal Jackie Smithas an argument to the CreateCustomer() method.

Usability Tips

Using voice with modifier keys to dynamically change the input mode while talking can seem a bit tricky at first. Here are some suggestions to make approaching this easier:

  • Create code in small pieces (shorter voice-to-code sessions). You don't have to create an entire line of code in a single session.
  • Take it easy. It's okay to pause while talking as you transition modifier keys between an up or down state.
  • Don't worry about precision. CodeRush is fairly tolerant of early/lagging modifier key presses and releases, so they don't have to occur right at the small pauses between the spoken words. As long as the transition occurs after the middle of the preceeding word, and before the middle of the next spoken word, CodeRush will snap the time of transition to the point between the two words.
  • You can invoke an alternate input mode exclusively for an entire voice-to-code session. So for example, if you need a string literal at the caret, you can hold down both the Ctrl and Shift keys (Ctrl to start the voice-to-code session, and Shift to switch to string literal input mode), and dictate the text of the string you need. When you're done, release both keys and CodeRush will insert the string containing your spoken words into the code.

More Voice Features

CodeRush contains powerful features for voice interaction in Visual Studio. Other posts documenting voice features in CodeRush:

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.