How to add Speech Recognition to Unity project?

Kanagalingam picture Kanagalingam · Sep 21, 2016 · Viewed 24.9k times · Source

I am presently working on a Augmented Reality project using Vuforia that uses Speech recognition to control the objects in Unity. I was just looking for a sample working code.

Answer

Programmer picture Programmer · Sep 21, 2016

Unity does not have this built in yet. They have been doing research on it for a long time and this will likely be added into Unity very soon. You can get the working Speech-to-Text(free) from the Assets store here. It is open source and you can help contribute to it if you find any problems.

As a side note, almost every OS has a Speech Recognition API. You easily make a plugin by wrapping all those API into a sing class in C# then use Unity's platform preprocessor directives to determine which one to call depending on which OS your game is running on.

Android:

SpeechRecognizer class.

see this project https://github.com/gsssrao/UnityAndroidSpeechRecognition

iOS:

SFSpeechRecognizer class

MacOS:

NSSpeechRecognizer class

Windows:

SpeechRecognitionEngine class

see this project https://github.com/LightBuzz/Speech-Recognition-Unity

Example:

class CrazySpeechRecognition
{
  #if UNITY_ANDROID  
    Use SpeechRecognizer class
  #endif

  #if UNITY_IOS
    Use SFSpeechRecognizer class
  #endif

  #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
    Use NSSpeechRecognizer class
  #endif

  #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
    Use SpeechRecognitionEngine class
  #endif 
}

The free Speech-to-Text from Unity is sadly discontinued, as stated in the link.