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
"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
void GetPercentOfTotal(double num1, double num2, double percent, out double answer) {
}
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
var tempAnswer = totalSum * percent
ref
and out
parameters. For example, consider the following code:public bool TimeIsValid(string accountingPeriod) {
}
result
as an out
parameter, like this:DateTime.TryParse(accountingPeriod, out var result)
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
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 Smith
as 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.