Bringing Microphone Support to Unity WebGL with Neocortex SDK
Unity, by default, does not support microphone input in WebGL builds. This limitation has caused frustration among developers trying to build voice-enabled web applications. Since browsers handle microphone access differently than native applications, Unity's WebGL builds lacks a built-in way to capture audio input.
Recognizing the need for microphone support in WebGL, we've introduced a solution in the latest version of our SDK. Now, Unity developers can capture user audio in WebGL builds seamlessly using the Neocortex Web Audio Receiver component.
How It Works
The key to making microphone support work in WebGL is the Neocortex WebGL Template. This template enables communication between the JavaScript frontend and the Unity WebGL application, facilitating audio transmission from the user's microphone to the Unity WebGL applications.
Key Features and Components:
- Neocortex Web Audio Receiver: This component functions similarly to Neocortex Audio Receiver but is optimized for WebGL, where native microphone support is absent.
- WebGL Audio Sample: The SDK now includes a sample project that demonstrates how to build and test microphone input in a WebGL environment.
- Neocortex WebGL Template: Developers must switch to the Neocortex WebGL Template to enable microphone support. This template is automatically imported, once the SDK is installed. You can also import it via Tools > Neocortex > Import WebGL Template. Developers can customize this template to suit their project needs visually.
- Microphone Dropdown UI Component: For non-WebGL projects, we have introduced a Microphone Dropdown component, allowing users to select their preferred microphone. WebGL projects do not require this since microphone selection is handled natively by the browser's permission settings.
How to Get Started
To start using microphone support in your Unity WebGL project with Neocortex SDK:
- Install the latest version of the Neocortex SDK.
- Switch your build settings to WebGL.
- Go to Edit > Project Settings > Player > Resolution and Presentation and set the WebGL Template to Neocortex.
- Import the sample projects included in the SDK via Package Manager.
- Open the WebGL Audio Sample scene and add it to the build settings.
- Build and test it out in your browser.
With the latest Neocortex SDK update, microphone support in Unity WebGL builds is now a reality. Developers no longer need to rely on complex workarounds or external JavaScript hacks to capture user audio. By leveraging the Neocortex WebGL Template and the Neocortex Web Audio Receiver, you can seamlessly integrate voice-enabled features into your WebGL projects.
Try it out today and let us know what you think!
Written by
Sercan Altundas
Date
Tue Feb 04 2025