AdvancedLogic

Pattern Matching

Extract variables from voice commands using curly brace syntax.

Dynamic Commands

Sometimes you want to capture dynamic data within a command, like setting a volume level or searching for a query. JSVoice's `addPatternCommand` facilitates this using a simple {key} syntax.

javascript
1voice.addPatternCommand('set volume to {level}', (args) => {
2    console.log(args.level); // "50", "max", etc.
3});

Arguments Object

The callback receives an `args` object containing key-value pairs for all extracted tokens.

javascript
1voice.addPatternCommand('move {direction} by {amount} pixels', (args) => {
2    // Command: "move up by 200 pixels"
3    
4    const dir = args.direction; // "up"
5    const dist = parseInt(args.amount); // 200
6    
7    moveObj(dir, dist);
8});