Share via


VoiceLiveSession class

Represents a WebSocket-based session for real-time voice communication with the Azure VoiceLive service.

This class manages the connection, handles real-time communication, and provides access to all interactive features including audio streaming, conversation management, and avatar control.

Constructors

VoiceLiveSession(string, TokenCredential | KeyCredential, string, AgentSessionConfig, VoiceLiveSessionOptions)

Creates an instance of VoiceLiveSession for agent-centric sessions.

VoiceLiveSession(string, TokenCredential | KeyCredential, string, string, VoiceLiveSessionOptions)

Creates an instance of VoiceLiveSession for model-centric sessions.

Properties

activeTurnId

Gets the current active audio turn ID.

connectionState

Gets the current connection state of the session.

isConnected

Indicates whether the session is currently connected to the Voice Live service.

sessionId

Gets the current session ID.

Methods

addConversationItem(ConversationRequestItem, SendEventOptions)

Adds a conversation item (message) to the conversation.

connect(ConnectOptions)

Establishes connection to the Voice Live service with authentication.

disconnect()

Disconnects from the Voice Live service and cleans up resources.

dispose()

Disposes the session and cleans up resources.

endAudioTurn(string, SendEventOptions)

Ends the current audio turn.

sendAudio(Uint8Array | ArrayBuffer, AudioStreamOptions)

Sends audio data to the service using turn-based or buffer-based approach.

sendEvent(ClientEventUnion, SendEventOptions)

Sends a custom client event to the service.

startAudioTurn(TurnOptions)

Starts a new audio turn for turn-based audio input.

subscribe(VoiceLiveSessionHandlers)

Subscribe to VoiceLive session events using strongly-typed handlers.

updateSession(RequestSession, SendEventOptions)

Updates the session configuration with the service.

Constructor Details

VoiceLiveSession(string, TokenCredential | KeyCredential, string, AgentSessionConfig, VoiceLiveSessionOptions)

Creates an instance of VoiceLiveSession for agent-centric sessions.

new VoiceLiveSession(endpoint: string, credential: TokenCredential | KeyCredential, apiVersion: string, agentConfig: AgentSessionConfig, options?: VoiceLiveSessionOptions)

Parameters

endpoint

string

The Voice Live service endpoint URL

credential

TokenCredential | KeyCredential

Azure TokenCredential or KeyCredential for authentication

apiVersion

string

API version to use for the Voice Live service

agentConfig
AgentSessionConfig

The agent configuration for the session

options
VoiceLiveSessionOptions

Optional configuration for the session

VoiceLiveSession(string, TokenCredential | KeyCredential, string, string, VoiceLiveSessionOptions)

Creates an instance of VoiceLiveSession for model-centric sessions.

new VoiceLiveSession(endpoint: string, credential: TokenCredential | KeyCredential, apiVersion: string, model: string, options?: VoiceLiveSessionOptions)

Parameters

endpoint

string

The Voice Live service endpoint URL

credential

TokenCredential | KeyCredential

Azure TokenCredential or KeyCredential for authentication

apiVersion

string

API version to use for the Voice Live service

model

string

The model name to use for the session

options
VoiceLiveSessionOptions

Optional configuration for the session

Property Details

activeTurnId

Gets the current active audio turn ID.

undefined | string activeTurnId

Property Value

undefined | string

connectionState

Gets the current connection state of the session.

ConnectionState connectionState

Property Value

isConnected

Indicates whether the session is currently connected to the Voice Live service.

boolean isConnected

Property Value

boolean

sessionId

Gets the current session ID.

undefined | string sessionId

Property Value

undefined | string

Method Details

addConversationItem(ConversationRequestItem, SendEventOptions)

Adds a conversation item (message) to the conversation.

function addConversationItem(item: ConversationRequestItem, options?: SendEventOptions): Promise<void>

Parameters

Returns

Promise<void>

connect(ConnectOptions)

Establishes connection to the Voice Live service with authentication.

function connect(options?: ConnectOptions): Promise<void>

Parameters

options
ConnectOptions

Returns

Promise<void>

disconnect()

Disconnects from the Voice Live service and cleans up resources.

function disconnect(): Promise<void>

Returns

Promise<void>

dispose()

Disposes the session and cleans up resources.

function dispose(): Promise<void>

Returns

Promise<void>

endAudioTurn(string, SendEventOptions)

Ends the current audio turn.

function endAudioTurn(turnId?: string, options?: SendEventOptions): Promise<void>

Parameters

turnId

string

Returns

Promise<void>

sendAudio(Uint8Array | ArrayBuffer, AudioStreamOptions)

Sends audio data to the service using turn-based or buffer-based approach.

function sendAudio(audioData: Uint8Array | ArrayBuffer, options?: AudioStreamOptions): Promise<void>

Parameters

audioData

Uint8Array | ArrayBuffer

Returns

Promise<void>

sendEvent(ClientEventUnion, SendEventOptions)

Sends a custom client event to the service.

function sendEvent(event: ClientEventUnion, options?: SendEventOptions): Promise<void>

Parameters

Returns

Promise<void>

startAudioTurn(TurnOptions)

Starts a new audio turn for turn-based audio input.

function startAudioTurn(options?: TurnOptions): Promise<string>

Parameters

options
TurnOptions

Returns

Promise<string>

subscribe(VoiceLiveSessionHandlers)

Subscribe to VoiceLive session events using strongly-typed handlers.

function subscribe(handlers: VoiceLiveSessionHandlers): VoiceLiveSubscription

Parameters

handlers
VoiceLiveSessionHandlers

Handler functions for different types of events

Returns

A subscription object that can be used to stop receiving events

updateSession(RequestSession, SendEventOptions)

Updates the session configuration with the service.

function updateSession(session: RequestSession, options?: SendEventOptions): Promise<void>

Parameters

session
RequestSession

Returns

Promise<void>