Powered by DocFX

Search Results for

    Setup Voice Control

    Editor

    1. Add Voice Control component to the scene, enable flag Auto Start and connect language model provider and speech source to it

    2. Setup voice commands. Each command is a phrase and an event that is triggered when the phrase is spoken. The figure below shows an example of 2 commands that are activated when you speak "start" and "stop"

      Voice Control

    3. Test voice control

      1. Create a script called VoiceControlListener.cs.

        using UnityEngine;
        
        public class VoiceControlListener : MonoBehaviour
        {
            public void OnStart()
            {
                Debug.Log("start");
            }
        
            public void OnStop()
            {
                Debug.Log("stop");
            }
        }
        
      2. Add the Voice Control Listener script and connect it to the Voice Control events

        Voice Control

      3. Press Play

        Voice Control Log

    Scripting

    using System.Collections.Generic;
    using Recognissimo.Components;
    using UnityEngine;
    
    public class VoiceControlExample : MonoBehaviour
    {
        private void Awake()
        {
            // Create components.
            var voiceControl = gameObject.AddComponent<VoiceControl>();
            var languageModelProvider = gameObject.AddComponent<StreamingAssetsLanguageModelProvider>();
            var speechSource = gameObject.AddComponent<MicrophoneSpeechSource>();
            
            // Setup speech source and language model provider as in the previous example.
            // ...
            
            // Bind speech processor dependencies.
            voiceControl.LanguageModelProvider = languageModelProvider;
            voiceControl.SpeechSource = speechSource;
    
            // Setup voice control
            voiceControl.AsapMode = true;
            
            voiceControl.Commands = new List<VoiceControlCommand>
            {
                new VoiceControlCommand("start|begin", () => Debug.Log("Start")),
                new VoiceControlCommand("stop", HandleStop)
            };
            
            voiceControl.StartProcessing();
        }
    
        private void HandleStop()
        {
            Debug.Log("Stop");
        }
    }
    

    Asap mode

    You can make Voice Control component faster by enabling Asap Mode flag.

    Voice Control Asap

    In this mode Voice Control component will use the preliminary recognition results to reduce response time.

    How to use regular expressions

    Voice Control supports regex patterns in phrases.

    Note that Recognissimo doesn't support patterns with multiple spaces.

    • Use "|" to separate phrases

      Voice Control Alternation

    • Use more complex syntax. Voice Control will trigger the event when the user says turn on the light, turn off the light, turn on light or turn off light

      Voice Control Regex