Skip to main content

Character Components

EstuaryCharacter

MonoBehaviour -- Represents a single AI character. Attach one per character in your scene.

Namespace: Estuary

Inspector Fields

FieldTypeDefaultDescription
CharacterIdstring""The character's ID from the Estuary Dashboard
PlayerIdstring""Player identifier. If blank, defaults to player_<device ID>
AutoConnectbooltrueConnect automatically on Start()
AutoStartVoiceSessionboolfalseStart voice session after connecting
StripActionsFromTextbooltrueRemove <action> tags from CurrentPartialResponse

Properties

PropertyTypeAccessDescription
CharacterIdstringget/setCharacter ID
PlayerIdstringget/setPlayer ID
CurrentSessionSessionInfogetSession info after connecting (null before)
CurrentPartialResponsestringgetAccumulated streaming response text
IsConnectedboolgettrue when this character's session is active
IsVoiceSessionActiveboolgettrue when a voice session is running
StripActionsFromTextboolget/setWhether to strip action tags from display text

Methods

MethodReturnsDescription
Connect()voidConnect synchronously (fire-and-forget wrapper)
ConnectAsync()TaskConnect to the server
Disconnect()voidDisconnect synchronously
DisconnectAsync()TaskDisconnect from the server
SendText(string text, bool? textOnly = null)voidSend a text message. textOnly defaults to true when no voice session is active
SendTextAsync(string text, bool? textOnly = null)TaskSend a text message asynchronously
StartVoiceSession()voidStart voice mode (WebSocket: sends start_voice; LiveKit: requests token)
EndVoiceSession()voidEnd voice mode

C# Events

EventSignatureDescription
OnConnectedAction<SessionInfo>Connection established
OnDisconnectedAction<string>Connection lost (reason)
OnBotResponseAction<BotResponse>Streaming text chunk received
OnBotResponseCompleteAction<string>Full response text when IsFinal is true
OnTranscriptAction<SttResponse>Speech-to-text result
OnActionReceivedAction<AgentAction>Action tag parsed from response
OnErrorAction<string>Error message

UnityEvents (Inspector)

These events appear in the Inspector and can be wired to any method without code:

EventParameterDescription
OnConnectedEventFires after connection
OnDisconnectedEventFires on disconnect
OnBotResponseEventstringFires with each response chunk's text
OnBotResponseCompleteEventstringFires with the full final response
OnTranscriptEventstringFires with transcript text
OnErrorEventstringFires with error messages

Default Player ID

When PlayerId is left blank, the SDK generates a default:

player_<first 8 characters of SystemInfo.deviceUniqueIdentifier>

This provides basic persistence across app sessions on the same device without requiring any setup.


EstuaryAudioSource

MonoBehaviour -- Plays streaming TTS audio from bot responses using a ring buffer for smooth, gap-free playback.

Namespace: Estuary

Inspector Fields

FieldTypeDefaultDescription
AutoInterruptOnUserSpeechboolfalseStop playback when the user starts speaking
MicrophoneRefEstuaryMicrophoneRequired if AutoInterruptOnUserSpeech is enabled
BufferLengthSecondsfloat5.0Ring buffer length in seconds

Properties

PropertyTypeAccessDescription
IsPlayingboolgettrue while audio is playing
CurrentMessageIdstringgetMessage ID of the audio currently playing

Methods

MethodReturnsDescription
EnqueueAudio(float[] samples, int sampleRate, string messageId)voidWrite PCM float samples into the ring buffer
EnqueueAudio(byte[] pcm16, int sampleRate, string messageId)voidWrite PCM16 bytes into the ring buffer (auto-converted to float)
StopPlayback()voidStop playback and clear the buffer

Events

EventSignatureDescription
OnPlaybackStartedActionAudio playback began
OnPlaybackCompleteActionAudio playback finished (buffer drained)
OnPlaybackInterruptedActionPlayback was stopped by an interrupt

How It Works

WebSocket mode: Bot audio arrives as base64-encoded PCM16 chunks in bot_voice events. EstuaryManager decodes the audio and calls EnqueueAudio. The component:

  1. Converts PCM16 bytes to float samples
  2. Resamples if the server sample rate differs from Unity's output rate
  3. Writes to a circular ring buffer
  4. Feeds samples to a streaming AudioClip via a PCM reader callback (OnAudioRead)

The ring buffer ensures smooth playback even when network jitter causes irregular chunk delivery.

LiveKit mode: Audio playback is handled by LiveKit's AudioStream, which creates its own AudioSource at runtime. EstuaryAudioSource still tracks the current message_id for interrupt handling but defers actual playback to LiveKit.

Auto-Interrupt

When AutoInterruptOnUserSpeech is enabled and the referenced EstuaryMicrophone detects speech while the bot is talking:

  1. Playback stops and the buffer is cleared
  2. OnPlaybackInterrupted fires
  3. A client_interrupt event is sent to the server with the current message_id
  4. The server stops generating audio for that message