Skip to content

@vowel.to/client v0.1.2-393


@vowel.to/client / index / Vowel

Class: Vowel

Defined in: lib/vowel/core/VowelClient.ts:74

Main Vowel client class

Example

ts
// vowel.client.ts
import { Vowel } from '@/lib/vowel';
import { tanstackRouterAdapter } from '@/lib/vowel/adapters';
import { router } from './router';

export const vowel = new Vowel({
  appId: 'your-app-id',
  router: tanstackRouterAdapter(router),
  routes: [
    { path: '/products', description: 'Browse products' },
    { path: '/cart', description: 'View cart' }
  ]
});

// Register custom actions
vowel.registerAction('searchProducts', {
  description: 'Search for products',
  parameters: {
    query: { type: 'string', description: 'Search query' }
  }
}, async (params) => {
  await searchProducts(params.query);
});

Constructors

Constructor

ts
new Vowel(config): Vowel;

Defined in: lib/vowel/core/VowelClient.ts:98

Parameters

ParameterType
configVowelClientConfig

Returns

Vowel

Accessors

appId

Get Signature

ts
get appId(): string | undefined;

Defined in: lib/vowel/core/VowelClient.ts:718

Get app ID

Returns

string | undefined


router

Get Signature

ts
get router(): RouterAdapter | undefined;

Defined in: lib/vowel/core/VowelClient.ts:726

Get router adapter (legacy)

Deprecated

Use navigationAdapter property instead

Returns

RouterAdapter | undefined


routes

Get Signature

ts
get routes(): VowelRoute[];

Defined in: lib/vowel/core/VowelClient.ts:733

Get configured routes

Returns

VowelRoute[]


session

Get Signature

ts
get session(): SessionManager;

Defined in: lib/vowel/core/VowelClient.ts:740

Get session manager (for internal use by action handlers)

Returns

SessionManager


voiceConfig

Get Signature

ts
get voiceConfig(): VowelVoiceConfig | undefined;

Defined in: lib/vowel/core/VowelClient.ts:747

Get voice configuration

Returns

VowelVoiceConfig | undefined


systemInstructionOverride

Get Signature

ts
get systemInstructionOverride(): string | undefined;

Defined in: lib/vowel/core/VowelClient.ts:754

Get system instruction override

Returns

string | undefined


state

Get Signature

ts
get state(): VoiceSessionState;

Defined in: lib/vowel/core/VowelClient.ts:761

Get current session state

Returns

VoiceSessionState


floatingCursor

Get Signature

ts
get floatingCursor(): FloatingCursorManager | undefined;

Defined in: lib/vowel/core/VowelClient.ts:789

Get floating cursor manager (if enabled)

Returns

FloatingCursorManager | undefined

Methods

isUserSpeaking()

ts
isUserSpeaking(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:768

Check if user is currently speaking (client-side VAD)

Returns

boolean


isAIThinking()

ts
isAIThinking(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:775

Check if AI is currently thinking/processing

Returns

boolean


isAISpeaking()

ts
isAISpeaking(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:782

Check if AI is currently speaking

Returns

boolean


registerAction()

ts
registerAction<T>(
   name, 
   definition, 
   handler): void;

Defined in: lib/vowel/core/VowelClient.ts:836

Register a custom action that the AI can perform

⚠️ CRITICAL: Actions MUST be registered BEFORE calling startSession()! Actions registered after the session starts will have NO EFFECT. Tool definitions are sent to the server during session initialization.

Type Parameters

Type ParameterDefault type
Tany

Parameters

ParameterTypeDescription
namestringAction name (will be used as tool name)
definitionVowelActionAction definition with parameters
handlerActionHandler<T>Function to execute when action is called

Returns

void

Example

ts
// ✅ CORRECT - Register before starting session
vowel.registerAction('addToCart', {
  description: 'Add product to shopping cart',
  parameters: {
    productId: {
      type: 'string',
      description: 'Product ID'
    },
    quantity: {
      type: 'number',
      description: 'Quantity',
      optional: true
    }
  }
}, async ({ productId, quantity = 1 }) => {
  await addToCart(productId, quantity);
});

// Then start the session
await vowel.startSession();

// ❌ WRONG - Too late!
await vowel.startSession();
vowel.registerAction('addToCart', ...);  // Won't work!

registerActions()

ts
registerActions(actions): void;

Defined in: lib/vowel/core/VowelClient.ts:864

Register multiple actions at once

Parameters

ParameterType
actionsRecord<string, { definition: VowelAction; handler: ActionHandler; }>

Returns

void

Example

ts
vowel.registerActions({
  searchProducts: {
    definition: { ... },
    handler: async (params) => { ... }
  },
  addToCart: {
    definition: { ... },
    handler: async (params) => { ... }
  }
});

unregisterAction()

ts
unregisterAction(name): void;

Defined in: lib/vowel/core/VowelClient.ts:875

Unregister an action

Parameters

ParameterType
namestring

Returns

void


getActionsConfig()

ts
getActionsConfig(): Record<string, VowelAction>;

Defined in: lib/vowel/core/VowelClient.ts:882

Get all registered actions as a record (for configuration)

Returns

Record<string, VowelAction>


executeAction()

ts
executeAction(name, params): Promise<ToolResult>;

Defined in: lib/vowel/core/VowelClient.ts:889

Execute a registered action

Parameters

ParameterType
namestring
paramsany

Returns

Promise<ToolResult>


hasAction()

ts
hasAction(name): boolean;

Defined in: lib/vowel/core/VowelClient.ts:904

Check if an action is registered

Parameters

ParameterType
namestring

Returns

boolean


addRoutes()

ts
addRoutes(routes): void;

Defined in: lib/vowel/core/VowelClient.ts:915

Add routes (useful for dynamic route registration)

Parameters

ParameterType
routesVowelRoute[]

Returns

void


setRoutes()

ts
setRoutes(routes): void;

Defined in: lib/vowel/core/VowelClient.ts:922

Set routes (replaces existing)

Parameters

ParameterType
routesVowelRoute[]

Returns

void


getCurrentPath()

ts
getCurrentPath(): string;

Defined in: lib/vowel/core/VowelClient.ts:929

Get current path

Returns

string


ts
navigate(path): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:942

Navigate to a path

Parameters

ParameterType
pathstring

Returns

Promise<void>


onStateChange()

ts
onStateChange(listener): () => void;

Defined in: lib/vowel/core/VowelClient.ts:959

Subscribe to state changes

Parameters

ParameterType
listener(state) => void

Returns

ts
(): void;
Returns

void


clearTranscripts()

ts
clearTranscripts(): void;

Defined in: lib/vowel/core/VowelClient.ts:994

Clear transcript history

Returns

void


clearError()

ts
clearError(): void;

Defined in: lib/vowel/core/VowelClient.ts:1001

Clear the current error state

Returns

void


getDarkMode()

ts
getDarkMode(): boolean;

Defined in: lib/vowel/core/VowelClient.ts:1008

Get current dark mode state

Returns

boolean


setDarkMode()

ts
setDarkMode(isDark): void;

Defined in: lib/vowel/core/VowelClient.ts:1015

Set dark mode state

Parameters

ParameterType
isDarkboolean

Returns

void


toggleDarkMode()

ts
toggleDarkMode(): void;

Defined in: lib/vowel/core/VowelClient.ts:1022

Toggle dark mode

Returns

void


exportState()

ts
exportState(options?): VoiceSessionState;

Defined in: lib/vowel/core/VowelClient.ts:1040

Export conversation state for later restoration

Parameters

ParameterTypeDescription
options?{ maxTurns?: number; }Export options
options.maxTurns?numberMaximum conversation turns to include (default: all)

Returns

VoiceSessionState

Serializable state object

Example

ts
// Save state to localStorage
const state = vowel.exportState({ maxTurns: 20 });
localStorage.setItem('vowel-conversation', JSON.stringify(state));

importState()

ts
importState(savedState): void;

Defined in: lib/vowel/core/VowelClient.ts:1058

Import conversation state from a previous session

Parameters

ParameterTypeDescription
savedStatePartial<VoiceSessionState>Previously exported state

Returns

void

Example

ts
// Restore state from localStorage
const saved = localStorage.getItem('vowel-conversation');
if (saved) {
  vowel.importState(JSON.parse(saved));
}

startSession()

ts
startSession(options?): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1106

Start a voice session Content window should be opened before calling this (in click handler for Shopify) Navigation is handled via BroadcastChannel, not WindowProxy

⚠️ CRITICAL for iOS Safari: This method MUST be called directly from a user gesture handler (click, touchstart, touchend). iOS Safari requires AudioContext creation and getUserMedia() calls to happen within the same user gesture event handler.

✅ Correct usage:

ts
button.addEventListener('click', async () => {
  await vowel.startSession(); // Called directly from click handler
});

❌ Incorrect usage (will fail on iOS):

ts
button.addEventListener('click', () => {
  setTimeout(() => {
    vowel.startSession(); // Too late - outside gesture handler
  }, 100);
});

Parameters

ParameterTypeDescription
options?{ restoreState?: Partial<VoiceSessionState>; }Session start options
options.restoreState?Partial<VoiceSessionState>Previously exported state to restore conversation context

Returns

Promise<void>

Example

ts
// Start fresh session
await vowel.startSession();

// Start with restored context
const saved = localStorage.getItem('vowel-conversation');
if (saved) {
  await vowel.startSession({ restoreState: JSON.parse(saved) });
}

notify()

ts
notify(
   eventType, 
   message, 
data?): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1167

Send a notification to the AI about an app event This allows programmatic triggering of AI responses

Parameters

ParameterTypeDescription
eventTypestringType of event (e.g., 'notification', 'resource_issue', 'session_start')
messagestringHuman-readable message describing the event
data?Record<string, any>Optional additional data/context

Returns

Promise<void>

Example

ts
// Notify AI about a game event
vowel.notify('resource_issue', 'Low on wood', { wood: 5, required: 20 });

// Notify about session start
vowel.notify('session_start', 'Voice control is now active');

stopSession()

ts
stopSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1226

Stop the current session

Returns

Promise<void>


pauseSession()

ts
pauseSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1262

Pause the current session (mute microphone, keep connection alive) This is useful for temporarily stopping audio input without disconnecting

Returns

Promise<void>

Example

ts
// Pause during a phone call
await vowel.pauseSession();

// Resume after the call
await vowel.resumeSession();

resumeSession()

ts
resumeSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1296

Resume a paused session (unmute microphone)

Returns

Promise<void>

Example

ts
await vowel.resumeSession();

toggleSession()

ts
toggleSession(): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1325

Toggle session on/off

Returns

Promise<void>


getAvailableMicrophones()

ts
getAvailableMicrophones(requirePermission): Promise<MediaDeviceInfo[]>;

Defined in: lib/vowel/core/VowelClient.ts:1351

Get available microphone devices

Parameters

ParameterTypeDefault valueDescription
requirePermissionbooleanfalseIf true, request getUserMedia first to get device labels. On iOS Safari, this MUST be called from a user gesture handler.

Returns

Promise<MediaDeviceInfo[]>

Promise resolving to array of MediaDeviceInfo for available audio input devices

Example

ts
const devices = await vowel.getAvailableMicrophones();
console.log('Available microphones:', devices.map(d => d.label));

hasMicrophonePermission()

ts
hasMicrophonePermission(): Promise<boolean>;

Defined in: lib/vowel/core/VowelClient.ts:1359

Check if microphone permission has been granted

Returns

Promise<boolean>

Promise resolving to true if permission granted, false otherwise


requestMicrophonePermission()

ts
requestMicrophonePermission(): Promise<boolean>;

Defined in: lib/vowel/core/VowelClient.ts:1368

Request microphone permission MUST be called from a user gesture handler on iOS Safari

Returns

Promise<boolean>

Promise resolving to true if permission granted, false otherwise


getCurrentMicrophone()

ts
getCurrentMicrophone(): MediaDeviceInfo | null;

Defined in: lib/vowel/core/VowelClient.ts:1385

Get the currently active microphone device

Returns

MediaDeviceInfo | null

MediaDeviceInfo for current device, or null if not available

Example

ts
const currentMic = vowel.getCurrentMicrophone();
if (currentMic) {
  console.log('Current microphone:', currentMic.label);
}

setMicrophoneDevice()

ts
setMicrophoneDevice(deviceId): void;

Defined in: lib/vowel/core/VowelClient.ts:1404

Set microphone device preference This will apply the device on the next microphone setup (next connection)

Parameters

ParameterTypeDescription
deviceIdstringThe device ID to use

Returns

void

Example

ts
const devices = await vowel.getAvailableMicrophones();
const usbMic = devices.find(d => d.label.includes('USB'));
if (usbMic) {
  vowel.setMicrophoneDevice(usbMic.deviceId);
}

switchMicrophoneDevice()

ts
switchMicrophoneDevice(deviceId): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1423

Switch microphone device during an active session This will reinitialize the microphone stream with the new device

Parameters

ParameterTypeDescription
deviceIdstringThe device ID to switch to

Returns

Promise<void>

Example

ts
const devices = await vowel.getAvailableMicrophones();
const newMic = devices[1];
await vowel.switchMicrophoneDevice(newMic.deviceId);

notifyEvent()

ts
notifyEvent(eventDetails, context?): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1480

Notify the AI about an app event This allows programmatic triggering of AI voice responses without user speech input

Parameters

ParameterTypeDescription
eventDetailsstringDescription of the event that occurred
context?Record<string, any>Optional context object to provide additional information

Returns

Promise<void>

Example

ts
// Simple notification
await vowel.notifyEvent('Order placed successfully!');

// Notification with context
await vowel.notifyEvent('New message received', {
  from: 'John Doe',
  preview: 'Hey, are you available?',
  timestamp: new Date().toISOString()
});

// Timer expiry notification
await vowel.notifyEvent('Your 5-minute timer has expired');

// Shopping cart update
await vowel.notifyEvent('Item added to cart', {
  productName: 'Wireless Headphones',
  price: 79.99,
  cartTotal: 3
});

sendText()

ts
sendText(text): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1504

Send text to the AI for processing Lower-level method for custom text-based interactions

Parameters

ParameterTypeDescription
textstringText to send to the AI

Returns

Promise<void>

Example

ts
// Ask a question programmatically
await vowel.sendText('What are the current promotions?');

// Provide context to the AI
await vowel.sendText('The user is looking at product ID 12345');

sendImage()

ts
sendImage(imageUrl): Promise<void>;

Defined in: lib/vowel/core/VowelClient.ts:1532

Send an image to the AI for processing Enables multimodal interactions where the AI can see and respond to images

Parameters

ParameterTypeDescription
imageUrlstringURL or data URI of the image to send

Returns

Promise<void>

Example

ts
// Send an image URL
await vowel.sendImage('https://example.com/product.jpg');

// Send a data URI (e.g., from canvas or file upload)
await vowel.sendImage('data:image/png;base64,iVBORw0KGgoAAAANS...');

// Combined with text context
await vowel.sendText('What do you see in this image?');
await vowel.sendImage(imageUrl);