KeenASR Unity is a Unity plugin that provides a simple-to-use C# interface via the KeenASR class to the underlying native iOS and Android KeenASR SDKs. The Unity plugin currently works with both the iOS and the Android versions of the KeenASR SDK.

Note that the KeenASR SDK only works on the device (not the simulator) on those platforms; we provide stub methods for Unity Player.

Installing the KeenASR Unity Plugin (tested in Unity 2019.4.0f1)

  1. Download the latest archive file for the Unity plugin. The archive contains both Android and iOS SDKs as well as the ASR Bundle.

  2. Unpack the archive in your Unity project root directory. You should end up with an Assets/Plugins/KeenASR directory in your project. The archive also contains a Assets/StreamingAssets/keenB2mQT-nnet3chain-en-us directory with the ASR Bundle (acoustic models) required by the KeenASR SDK.

  3. Make sure Unity is configured to build for either iOS or Android; the editor version of the plugin provides only stubs.

  4. As of plugin version 0.3, all settings in XCode that are related to the KeenASR SDK are applied automatically by the Assets/Plugins/KeenASR/Editor/PostBuildProcess.cs script. Be sure to review and edit the settings for the microphone usage description in this file. Alternatively, comment out that sectio and update microphone usage description in Unity iOS Player settings.

  5. For Android builds, modify the following settings under Build Settings -> Player Settings:

    Minimum API Level: 21

    If using Gradle you will need to set: BuildSettings->Publishing Settings->Minify->Release to None

  6. For Android builds, the AndroidManifest.xml file in Assets/Plugins/KeenASR/Android/KeenASRUnityBinding.aar archive requires RECORD_AUDIO permission. This file is merged with the app’s AndroidManifest.xml file during the Unity build, and the user will be prompted to allow the app to record the audio on application startup. The app will also prompt the user for a number of additional permissions. If you disable the so called, “dangerous permissions” by creating your own AndroidManifest.xml file in Assets/Plugins/Android directory, make sure the user is prompted for the record audio permissions before the KeenASR SDK is initialized. For more information refer to Unity documentation.

  7. If you are using a custom ASR Bundle separately provided to you by Keen Research, remove the Assets/StreamingAssets/keenB2mQT-nnet3chain-en-us/ directory and copy the custom ASR bundle instead so that the StreamingAssets directory contains a subdirectory with the new bundle.

  8. If you are upgrading from a previous plugin version, we recommend you completely remove the old plugin (Assets/Plugins/KeenASR directory) before installing the new plugin version.

  9. Make sure that directories corresponding to specific platforms (iOS/Android) in the KeenASR plugin directory are only included for those platforms; meaning, Assets/Plugins/KeenASR/iOS is only used for iOS builds and Assets/Plugins/KeenASR/Android is only for Android builds. This can be specified by selecting all the files in the relevan folder in the Unity Project tab, then checking appropriate checkboxes in the inspector.

Adding Speech Recognition Functionality to Your App

Review the Assets/Plugins/KeenASR/KeenASR.cs file, which provides a high-level interface to the SDK. We strongly recommend you review the documentation for the iOS framework familiarize yourself with the high-level concepts. The Unity plugin provides access to most of the functionality available in the iOS and Android SDKs.

See sample code for using the plugin from within Unity. This example shows how to initialize the SDK; it presents a “Start Listening” button on the screen and logs partial and final results on the console (they are not shown on the screen).