Share via


VoiceLiveClient class

The VoiceLive client provides session management for real-time conversational AI capabilities.

This client acts as a factory for creating VoiceLiveSession instances, which handle the actual WebSocket connections and real-time interactions with the service.

Constructors

VoiceLiveClient(string, TokenCredential | KeyCredential, VoiceLiveClientOptions)

Creates an instance of VoiceLiveClient with endpoint and credential.

Properties

apiVersion
endpoint

Methods

createSession(RequestSession, CreateSessionOptions)

Creates a new VoiceLiveSession for real-time voice communication with session configuration.

createSession(SessionTarget, CreateSessionOptions)

Creates a new VoiceLiveSession using a session target (model or agent).

Example

Model-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = client.createSession({ model: "gpt-4o-realtime-preview" });

Example

Agent-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = client.createSession({
  agent: { agentName: "my-agent", projectName: "my-project" },
});
createSession(string, CreateSessionOptions)

Creates a new VoiceLiveSession for real-time voice communication.

startSession(RequestSession, StartSessionOptions)

Creates and immediately connects a new VoiceLiveSession with session configuration.

startSession(SessionTarget, StartSessionOptions)

Creates and immediately connects a new VoiceLiveSession using a session target.

Example

Model-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = await client.startSession({ model: "gpt-4o-realtime-preview" });

Example

Agent-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = await client.startSession({
  agent: { agentName: "my-agent", projectName: "my-project" },
});
startSession(string, StartSessionOptions)

Creates and immediately connects a new VoiceLiveSession.

Constructor Details

VoiceLiveClient(string, TokenCredential | KeyCredential, VoiceLiveClientOptions)

Creates an instance of VoiceLiveClient with endpoint and credential.

new VoiceLiveClient(endpoint: string, credential: TokenCredential | KeyCredential, options?: VoiceLiveClientOptions)

Parameters

endpoint

string

The Voice Live service endpoint URL

credential

TokenCredential | KeyCredential

Azure TokenCredential or KeyCredential for authentication

options
VoiceLiveClientOptions

Optional configuration for the client

Property Details

apiVersion

string apiVersion

Property Value

string

endpoint

string endpoint

Property Value

string

Method Details

createSession(RequestSession, CreateSessionOptions)

Creates a new VoiceLiveSession for real-time voice communication with session configuration.

function createSession(sessionConfig: RequestSession, sessionOptions?: CreateSessionOptions): VoiceLiveSession

Parameters

sessionConfig
RequestSession

Session configuration including model and other settings

sessionOptions
CreateSessionOptions

Optional configuration specific to this session

Returns

A new VoiceLiveSession instance ready to connect

createSession(SessionTarget, CreateSessionOptions)

Creates a new VoiceLiveSession using a session target (model or agent).

Example

Model-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = client.createSession({ model: "gpt-4o-realtime-preview" });

Example

Agent-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = client.createSession({
  agent: { agentName: "my-agent", projectName: "my-project" },
});
function createSession(target: SessionTarget, sessionOptions?: CreateSessionOptions): VoiceLiveSession

Parameters

target
SessionTarget

The session target specifying either a model or agent

sessionOptions
CreateSessionOptions

Optional configuration specific to this session

Returns

A new VoiceLiveSession instance ready to connect

createSession(string, CreateSessionOptions)

Creates a new VoiceLiveSession for real-time voice communication.

function createSession(model: string, sessionOptions?: CreateSessionOptions): VoiceLiveSession

Parameters

model

string

The model name to use for the session (e.g., "gpt-4o-realtime-preview")

sessionOptions
CreateSessionOptions

Optional configuration specific to this session

Returns

A new VoiceLiveSession instance ready to connect

startSession(RequestSession, StartSessionOptions)

Creates and immediately connects a new VoiceLiveSession with session configuration.

function startSession(sessionConfig: RequestSession, sessionOptions?: StartSessionOptions): Promise<VoiceLiveSession>

Parameters

sessionConfig
RequestSession

Session configuration including model and other settings

sessionOptions
StartSessionOptions

Optional configuration specific to this session

Returns

Promise<VoiceLiveSession>

A connected VoiceLiveSession instance

startSession(SessionTarget, StartSessionOptions)

Creates and immediately connects a new VoiceLiveSession using a session target.

Example

Model-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = await client.startSession({ model: "gpt-4o-realtime-preview" });

Example

Agent-centric session

import { DefaultAzureCredential } from "@azure/identity";
import { VoiceLiveClient } from "@azure/ai-voicelive";

const credential = new DefaultAzureCredential();
const endpoint = "https://your-resource.cognitiveservices.azure.com";
const client = new VoiceLiveClient(endpoint, credential);

const session = await client.startSession({
  agent: { agentName: "my-agent", projectName: "my-project" },
});
function startSession(target: SessionTarget, sessionOptions?: StartSessionOptions): Promise<VoiceLiveSession>

Parameters

target
SessionTarget

The session target specifying either a model or agent

sessionOptions
StartSessionOptions

Optional configuration specific to this session

Returns

Promise<VoiceLiveSession>

A connected VoiceLiveSession instance

startSession(string, StartSessionOptions)

Creates and immediately connects a new VoiceLiveSession.

function startSession(model: string, sessionOptions?: StartSessionOptions): Promise<VoiceLiveSession>

Parameters

model

string

The model name to use for the session (e.g., "gpt-4o-realtime-preview")

sessionOptions
StartSessionOptions

Optional configuration specific to this session

Returns

Promise<VoiceLiveSession>

A connected VoiceLiveSession instance