Skip to content

Voice Commands

bardsodal edited this page Dec 15, 2021 · 4 revisions

Voice commands

There are two main ways of using voice commands in BDK. The first is to use our script VoiceCommand.cs. This script allows you to type the required command word/phrase and add a Unity event that will fire once the word or phrase has been spoken.

Voice Command script

The other way is to use the built in voice recognition in one of your own scripts. There are two ways to do this. The first is to add a command with an Action attached to it. A command can only be added once, so this method can be used for unique commands (with only one recipient):

public void Start()
{
    InputManager.Instance.AddPhraseForVoiceRecognizion("your command", ActionToCallWhenRecognized);
}

private void ActionToCallWhenRecognized()
{
    // do something
}

The second way is to send a command to listen for, but listen for the OnPhraseRecognized event. This is useful if you require several scripts to respond to the same command.

string commandToListenFor = "command";
public void Start()
{
    InputManager.Instance.AddPhraseForVoiceRecognizion(commandToListenFor);
    InputManager.Instance.OnPhraseRecognized += ActionToCallWhenRecognized;
}

private void ActionToCallWhenRecognized(InputSource voice)
{
    if(voice.message.Equals(commandToListenFor))
    {
        // do something
    }
}