v151 · Web API · Speech

Voice Command Mode

For voice command interfaces, unspokenPunctuation: false is the right default. Auto-inserted punctuation corrupts exact-match keywords: "play music" becomes "play music." and the command fails. This demo shows why command parsers must opt out.

Checking SpeechRecognition and unspokenPunctuation support…

command listener

unspokenPunctuation:
Ready — click Listen
Say a command

Effect:

Waiting for a command…

command registry

Available commands (exact-match)
Ready. Click Listen to start.

why false is the right default for commands

With unspokenPunctuation: true (dictation mode):
User says: "play music" → engine returns: "play music." → command lookup fails
User says: "go to next slide" → engine returns: "go to next slide." → no match

With unspokenPunctuation: false (command mode):
User says: "play music" → engine returns: "play music" → ✓ matched
User says: "go to next slide" → engine returns: "go to next slide" → ✓ matched

code

// DICTATION — unspokenPunctuation: true
// Auto-punctuates pauses and sentence endings.
// Use for note-taking, messaging, document creation.
const dictation = new SpeechRecognition();
dictation.unspokenPunctuation = true;
dictation.continuous = true;
dictation.interimResults = true;

// COMMANDS — unspokenPunctuation: false (default)
// Raw words only — no trailing periods, no commas.
// Use for voice commands, search, code dictation.
const commands = new SpeechRecognition();
commands.unspokenPunctuation = false; // default, but explicit
commands.continuous = true;
commands.interimResults = true;

// Build a strict command matcher
const COMMANDS = {
  'play music':      () => player.play(),
  'pause music':     () => player.pause(),
  'next slide':      () => deck.next(),
  'previous slide':  () => deck.prev(),
  'go home':         () => location.href = '/',
};

commands.onresult = ({ results }) => {
  const transcript = results[results.length - 1][0].transcript.trim().toLowerCase();
  const handler = COMMANDS[transcript]; // exact match
  if (handler) handler();
  else console.log('Unknown command:', transcript);
};

see also

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗