A key functionality that brings an application from speech to text to a complete dictation solution is Commands. Put your users in the driver seat to control their workflow by defining commands to insert templates, navigate the application, automate repetitive tasks, and more!
Commands are set in dictation configuration when directly calling the /transcribe API or when using the Dictation Web Component.Explanation of parameters used in /transcribe command configuration:
Parameter
Type
Definition
id
string
Identifier for the command when it is detected by the speech recognizer.
phrases
string array
Word sequence that is spoken to trigger the command.
variables
string array
Placeholder in phrases to define multiple words that should trigger the command. The word options are defined as a enum list within the variables object.
When configured commands are recognized by the server, the command object will be returned over the web socket (as opposed to the transcript object for speech recognized text), which includes the command ID and variables that the integrating application uses to execute the defined action.Below are some examples, including both the request configuration and server response.
Note that the id, phrases, and variables shown below are mere examples. Define these values as needed for your own commands. Additionally, your application must manage the actions to be triggered by recognized commands.
Command to navigate around your application (e.g., to a section within the current document template). The command includes a defined list of words that can be recognized for the section_key variable.
Command to select text in the editor. The command includes a defined list of words that can be recognized for the select_range variable. Your application can define different delete actions for each of the options, or add more complex handling for selecting specific words mentioned in the command utterance.
Copy
Ask AI
commands: [ { id: "select_range", phrases: ["select {select_range}"], variables: [ { key: "select_range", type: "enum", enum: ["all", "the last word", "the last sentence"] } ] } ]
Command to delete text. The command includes a defined list of words that can be recognized for the delete_range variable. Your application can define different delete actions for each of the options!
Copy
Ask AI
commands: [ { id: "delete_range", phrases: ["delete {delete_range}"], variables: [ { key: "delete_range", type: "enum", enum: ["everything", "the last word", "the last sentence", "that"] } ] }]
The three commands defined above can be combined into one dictation configuration with accompanying Javascript to execute the actions. The below example includes navigation commands to move between sections within the SOAP note template, delete text command to remove last word, sentence, or paragraph, and select text commands to select text within the active text field:
Full Dictation Command Configuration
Copy
Ask AI
dictation.dictationConfig = { primaryLanguage: "en", spokenPunctuation: true, automaticPunctuation: false, commands: [ { id: "go_to_section", phrases: ["go to {section_key} section"], variables: [ { key: "section_key", type: "enum", enum: ["subjective", "objective", "assessment", "plan", "next", "previous"] } ] }, { id: "delete_range", phrases: ["delete {delete_range}"], variables: [ { key: "delete_range", type: "enum", enum: ["everything", "the last word", "the last sentence", "that"] } ] }, { id: "select_range", phrases: ["select {select_range}"], variables: [ { key: "select_range", type: "enum", enum: ["all", "the last word", "the last sentence"] } ] } ]};dictation.addEventListener("transcript", (e) => { const { data } = e.detail; const currentTextarea = textareas[activeIndex]; const interimTranscriptEl = document.getElementById("interimTranscript"); if (data.isFinal) { // Instead of appending at the end, insert the text at the user's cursor // or replace the selected range. const start = currentTextarea.selectionStart; const end = currentTextarea.selectionEnd; const insertedText = data.text + " "; const before = currentTextarea.value.slice(0, start); const after = currentTextarea.value.slice(end); currentTextarea.value = before + insertedText + after; const newCursorPos = start + insertedText.length; currentTextarea.setSelectionRange(newCursorPos, newCursorPos); interimTranscriptEl.classList.add("hidden"); } else { interimTranscriptEl.classList.remove("hidden"); interimTranscriptEl.innerText = data.rawTranscriptText; }});dictation.addEventListener("command", (e) => { const { data } = e.detail; document.getElementById("interimTranscript").classList.add("hidden"); const commandOutput = document.getElementById("commandOutput"); if (data.id === "go_to_section") { const section = data.variables.section_key.toLowerCase(); if (section === "next") { if (activeIndex < textareas.length - 1) { activeIndex++; textareas[activeIndex].focus(); } } else if (section === "previous") { if (activeIndex > 0) { activeIndex--; textareas[activeIndex].focus(); } } else { const index = textareas.findIndex(el => el.id.toLowerCase() === section); if (index !== -1) { activeIndex = index; textareas[activeIndex].focus(); } } commandOutput.innerHTML = "Command: " + data.id + " with section key: " + section; } else if (data.id === "delete_range") { const range = data.variables.delete_range.toLowerCase(); const currentTextarea = textareas[activeIndex]; let content = currentTextarea.value; if (range === "everything") { currentTextarea.value = ""; } else if (range === "the last word") { let words = content.trim().split(/\s+/); words.pop(); currentTextarea.value = words.join(" ") + (words.length > 0 ? " " : ""); } else if (range === "the last sentence") { let sentences = content.match(/[^.!?]+[.!?]*\s*/g); if (sentences && sentences.length > 0) { sentences.pop(); currentTextarea.value = sentences.join(""); } } else if (range === "that") { // If there's a selection, delete it; otherwise, delete the last word. const start = currentTextarea.selectionStart; const end = currentTextarea.selectionEnd; if (start !== end) { currentTextarea.value = content.slice(0, start) + content.slice(end); } else { let words = content.trim().split(/\s+/); words.pop(); currentTextarea.value = words.join(" ") + (words.length > 0 ? " " : ""); } } commandOutput.innerHTML = "Command: " + data.id + " with delete range: " + range; } else if (data.id === "select_range") { const range = data.variables.select_range.toLowerCase(); const currentTextarea = textareas[activeIndex]; const content = currentTextarea.value; if (range === "all") { currentTextarea.focus(); currentTextarea.setSelectionRange(0, content.length); } else if (range === "the last word") { const trimmedContent = content.trimEnd(); const lastSpaceIndex = trimmedContent.lastIndexOf(" "); const start = lastSpaceIndex !== -1 ? lastSpaceIndex + 1 : 0; currentTextarea.focus(); currentTextarea.setSelectionRange(start, trimmedContent.length); } else if (range === "the last sentence") { const sentences = content.match(/[^.!?]+[.!?]*\s*/g); if (sentences && sentences.length > 0) { let sum = 0; for (let i = 0; i < sentences.length - 1; i++) { sum += sentences[i].length; } const lastSentence = sentences[sentences.length - 1]; const start = sum; const end = start + lastSentence.length; currentTextarea.focus(); currentTextarea.setSelectionRange(start, end); } } commandOutput.innerHTML = "Command: " + data.id + " with select range: " + range; }});
Click here for more info on how to build commands effectively.
Use of commands is optional for dictation configuration. They should be configured based on how the integrating application will perform the actions.Please contact us to report errors, or for more information on this feature.