Speech To Text STT In Unity by codemaker2015 - 1

Games & ProjectsInputs

Simple game in unity to move a game object using up, down, left and right voice inputs

Unity 2018.2.0f2Unknown LicenseUpdated 41 days agoCreated on January 15th, 2020
Go to source

Speech Recognition in Unity

Speech Recognition using C# and Unity3D.

Football game in Unity3D

Prerequisites

To run the project, you’ll need the following software components:

  • Unity3D 2019.2+

Source Code

We’ll be using the KeywordRecognizer class to detect the voice commands:


    public string[] keywords = new string[] { "up", "down", "left", "right" };
    public ConfidenceLevel confidence = ConfidenceLevel.Medium;
    public float speed = 1;

    public Text results;
    public Image target;

    protected PhraseRecognizer recognizer;
    protected string word = "right";

    private void Start()
    {
        if (keywords != null)
        {
            recognizer = new KeywordRecognizer(keywords, confidence);
            recognizer.OnPhraseRecognized += Recognizer_OnPhraseRecognized;
            recognizer.Start();
        }
    }

    private void Recognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
    {
        word = args.text;
        results.text = "You said: <b>" + word + "</b>";
    }

    private void OnApplicationQuit()
    {
        if (recognizer != null && recognizer.IsRunning)
        {
            recognizer.OnPhraseRecognized -= Recognizer_OnPhraseRecognized;
            recognizer.Stop();
        }
    }

Exporting the project

KeywordRecognizer is available for Windows Standalone and Windows Store (Windows 8.1 or Windows 10):

  • Windows
  • Android
Show all projects by codemaker2015