How to automate Voice Control to manipulate the currently selected text?
Sorry I have zero knowledge of JavaScript but I do have somewhat of a solution for you using only AppleScript without the need for Automator.
This following AppleScript code will take the selected text in any application, replace the spaces with hyphens then will replace your original selected text with the new hyphenated text.
-- Copies Selected Text To The Clipboard
tell application &quot;System Events&quot; to keystroke &quot;c&quot; using {command down}
delay 0.1

-- Uses The Text From The Clipboard And Replaces Space Characters With A Hyphen
set hyphenatedText to hyphenateText(the clipboard, &quot; &quot;, &quot;-&quot;)
delay 0.1

-- Inserts The New Hyphenated Text Replacing The Original Selected Text
tell application &quot;System Events&quot; to keystroke hyphenatedText

(* 
someText is the selected text containing the characters to be replaced
replaceTheseListItems are characters from original text which you want replaced
replacementListItems replacement text characters 
*)
on hyphenateText(someText, replaceTheseListItems, replacementListItems)
    set originalText to someText
    set AppleScript's text item delimiters to replaceTheseListItems
    set tempText to text items of originalText
    set text item delimiters to replacementListItems
    set cleanedText to tempText as text
end hyphenateText

Save the AppleScript code as a .scpt file (Hyphenate Selected Text.scpt). Then open Finder and select your new script file.  Once the file is selected, and with voice control activated, simply say the command “Make This Speakable”.  When the new dictation command dialog box opens, Assign it a new voice command

For demonstration purposes I added this script file to the script menu and ran it from there