Skip to main content

Voice AI quickstart

To build your first voice AI app for Unity, use the following quickstart and the agent sample project included in the LiveKit Unity package. Otherwise follow the getting started guide below.

Building for WebGL

This quickstart covers the LiveKit Unity SDK for native platforms (macOS, Windows, Linux, iOS, and Android). To build for WebGL, use the Unity (WebGL) SDK instead.

Voice AI quickstart

Create a voice AI agent in less than 10 minutes.

Unity Voice Agent

A cross-platform voice AI assistant app built with Unity.
GitHublivekit/client-sdk-unity

Getting started guide

This guide covers installing the LiveKit Unity SDK, connecting to a room, and publishing media.

Platform support

LiveKit officially supports Unity 2022.3 and later. Testing covers Unity 2022.3.62 and Unity 6000.3.10.

The supported platforms are:

  • macOS
  • Windows
  • Linux
  • iOS
  • Android

SDK installation

Install the LiveKit Unity SDK from a Git URL or the OpenUPM registry.

Install with Git

Click the Add + menu in the Package Manager toolbar, select Add package from git URL, and enter: https://github.com/livekit/client-sdk-unity.git

For more details, see the Unity docs on installing packages from Git URLs .

Install with OpenUPM

The package is also available in the OpenUPM package registry . To import it, follow the manual installation instructions .

Permissions

Microphone and camera capture require platform permissions:

PlatformRequired permissions
iOS and macOSSet Microphone Usage Description (and Camera Usage Description for video) in Project Settings > Player.
AndroidDeclare android.permission.RECORD_AUDIO (and android.permission.CAMERA for video) in a custom AndroidManifest.xml under Assets/Plugins/Android, and request access at runtime with Permission.RequestUserPermission .
Windows/LinuxDevice permissions are typically managed by the OS or user settings.

The Meet  and agents  sample projects include a working Android manifest and runtime permission checks you can copy.

Connecting to LiveKit

Add the following code to connect to a room:

IEnumerator ConnectToRoom()
{
var serverUrl = "<your LiveKit server URL>";
var token = "<generate a token>";
var room = new Room();
var connect = room.Connect(serverUrl, token, new RoomOptions());
yield return connect;
}

In production, use a token source to generate a token and connect to a room. For more details, see the Meet sample app .

Publishing the microphone

The SDK offers two ways to capture and publish audio:

  • Platform audio (recommended) routes audio through WebRTC's native audio device module. It provides echo cancellation, noise suppression, and automatic gain control, and it plays remote audio back automatically. This is the right choice for voice agents and calls.
  • Unity audio routes audio through Unity's audio engine. Choose it when you need to run audio through Unity's mixer or apply your own processing. It does not provide echo cancellation.

Platform audio

Create the PlatformAudio instance before you connect. Automatic playback of remote audio is only enabled for a PlatformAudio that exists at connect time, so initializing it after Connect leaves remote audio silent.

// Create this before calling room.Connect
_platformAudio = new PlatformAudio();
IEnumerator PublishMicrophone(Room room)
{
// Start capture. On Android, this awaits the microphone permission prompt.
yield return _platformAudio.StartRecording();
// Default options enable echo cancellation, noise suppression, and auto gain control.
var source = new PlatformAudioSource(_platformAudio, AudioProcessingOptions.Default);
var track = LocalAudioTrack.CreateAudioTrack("my-audio-track", source, room);
var options = new TrackPublishOptions { Source = TrackSource.SourceMicrophone };
var publish = room.LocalParticipant.PublishTrack(track, options);
yield return publish;
if (publish.IsError)
{
Debug.LogError("Failed to publish microphone track");
source.Dispose();
}
}

With platform audio, remote audio plays back automatically. You don't need to handle subscribed audio tracks yourself.

Unity audio

IEnumerator PublishMicrophone(Room room)
{
// Warm up the microphone. On mobile, this triggers the permission prompt.
Microphone.Start(null, true, 10, 44100);
var audioObject = new GameObject("Microphone");
var source = new MicrophoneSource(Microphone.devices[0], audioObject);
var track = LocalAudioTrack.CreateAudioTrack("my-audio-track", source, room);
var options = new TrackPublishOptions { Source = TrackSource.SourceMicrophone };
var publish = room.LocalParticipant.PublishTrack(track, options);
yield return publish;
if (publish.IsError)
{
Object.Destroy(audioObject);
yield break;
}
source.Start();
}

On the Unity audio path, you play remote audio yourself by attaching each subscribed audio track to an AudioSource. See Subscribing to tracks for the receiving side.

Publishing the camera

Add the following code to capture and publish a camera track:

IEnumerator PublishCamera(Room room)
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (!Application.HasUserAuthorization(UserAuthorization.WebCam)) yield break;
var webCamTexture = new WebCamTexture(WebCamTexture.devices[0].name, 1280, 720, 30);
webCamTexture.Play();
var source = new WebCameraSource(webCamTexture);
var track = LocalVideoTrack.CreateVideoTrack("my-video-track", source, room);
var options = new TrackPublishOptions
{
VideoCodec = VideoCodec.H264,
Source = TrackSource.SourceCamera
};
var publish = room.LocalParticipant.PublishTrack(track, options);
yield return publish;
if (publish.IsError) yield break;
// Start the source and pump frames on each Unity update.
source.Start();
StartCoroutine(source.Update());
}

Next steps

The following resources are useful for getting started with LiveKit on Unity.