Skip to main content

AACVoiceAPI

aac-voice-api


Defined in: AACVoiceAPI.ts:49

Constructors​

Constructor​

new AACVoiceAPI(): AACVoiceAPI;

Defined in: AACVoiceAPI.ts:55

Returns​

AACVoiceAPI

Methods​

addVoiceCommand()​

addVoiceCommand(
name,
action,
options?): Promise`<CommandAddResult>`;

Defined in: AACVoiceAPI.ts:258

Adds a voice command to the system. Optionally fetches and registers synonyms from DataMuse API.

Parameters​

ParameterType

name

string

action

() => void

options?

{ active?: boolean; description?: string; fetchSynonyms?: boolean; numberOfSynonyms?: number; }

options.active?

boolean

options.description?

string

options.fetchSynonyms?

boolean

options.numberOfSynonyms?

number

Returns​

Promise<CommandAddResult>

Promise<CommandAddResult> Result object with command and synonym information


clearCommands()​

clearCommands(): void;

Defined in: AACVoiceAPI.ts:314

Allows user to remove all game commands from system

Returns​

void


clearSessionLogs()​

clearSessionLogs(): void;

Defined in: AACVoiceAPI.ts:452

Clears all session logs. Removes all stored transcriptions, matched commands, and resets the log counter.

Note: This does NOT clear CommandHistory. Use displayCommandHistory() to access the separate command-only history.

Returns​

void

Example​

api.clearSessionLogs();
console.log('Session logs cleared');

displayCommandHistory()​

displayCommandHistory(): void;

Defined in: AACVoiceAPI.ts:243

Displays all game Commands in a toggleable modal

Returns​

void


downloadLogsAsJSON()​

downloadLogsAsJSON(filename): void;

Defined in: AACVoiceAPI.ts:405

Downloads session logs as a JSON file (browser only). Triggers a browser download with the specified filename.

Note: This method only works in browser environments. For Node.js, use getSessionLogsData() instead.

Parameters​

ParameterTypeDefault valueDescription

filename

string

'aac-session-log.json'

Name of the file to download (default: 'aac-session-log.json')

Returns​

void

Example​

// Download logs with default filename
api.downloadLogsAsJSON();

// Download with custom filename
api.downloadLogsAsJSON('my-session-2024-01-15.json');

exportSessionLogs()​

exportSessionLogs(): string;

Defined in: AACVoiceAPI.ts:365

Exports all finalized session logs as a formatted JSON string.

Use this method to get comprehensive analytics data including:

  • Full transcription text with timestamps
  • Matched commands with confidence scores
  • Synonym resolution details (library vs API)
  • Error messages for failed command executions
  • Speaker IDs (in multi-speaker mode)

Returns​

string

Pretty-printed JSON string of all session logs

Example​

const json = api.exportSessionLogs();
console.log(json);

getCommands()​

getCommands(): string[] | [];

Defined in: AACVoiceAPI.ts:307

Allows user to see a list of all known game commands

Returns​

string[] | []

a list of all known game commands


getMode()​

getMode(): string;

Defined in: AACVoiceAPI.ts:323

Gets the current mode of operation

Returns​

string

The current mode ('offline' or 'online'), or null if not initialized


getSessionLogs()​

getSessionLogs(): LogEntry[];

Defined in: AACVoiceAPI.ts:435

Gets all finalized session logs. Returns detailed information about each transcription and matched commands.

Use Logger for comprehensive analytics data. Use CommandHistory (via displayCommandHistory()) for simple UI display.

Returns​

LogEntry[]

Array of finalized log entries

Example​

const logs = api.getSessionLogs();
logs.forEach(log => {
console.log(`[${log.timestamp}] "${log.transcriptionText}"`);
console.log(` Matched ${log.matchedCommands.length} command(s)`);
});

getSessionLogsData()​

getSessionLogsData(): LogEntry[];

Defined in: AACVoiceAPI.ts:383

Gets the raw log data as a JavaScript object. Useful for Node.js environments where manual file operations are needed.

Returns​

LogEntry[]

Array of log entry objects

Example​

// Node.js usage
const fs = require('fs');
const logData = api.getSessionLogsData();
fs.writeFileSync('session-logs.json', JSON.stringify(logData, null, 2));

getTranscriptionLogs()​

getTranscriptionLogs(): string[];

Defined in: AACVoiceAPI.ts:235

Retrieves the full transcription history from the Whisper module.

Returns​

string[]

An array of transcription log entries, each containing the transcribed text and its corresponding timestamp.


initiate()​

initiate(config): Promise`<void>`;

Defined in: AACVoiceAPI.ts:82

Parameters​

ParameterTypeDescription

config

voiceAPIConfig

Configuration object used to initialize the API.

Returns​

Promise<void>

Throws​

Throws an error if modelUrl is not provided when initiating in online mode.


initiateOnlineMultiSpeaker()​

initiateOnlineMultiSpeaker(domainName): Promise`<void>`;

Defined in: AACVoiceAPI.ts:141

Initialize online mode with speaker separation

Parameters​

ParameterType

domainName

string

Returns​

Promise<void>


initiateOnlineSingleSpeaker()​

initiateOnlineSingleSpeaker(domainName): Promise`<void>`;

Defined in: AACVoiceAPI.ts:129

Initialize online mode for single speaker

Parameters​

ParameterType

domainName

string

Returns​

Promise<void>


isRegistered()​

isRegistered(name): boolean;

Defined in: AACVoiceAPI.ts:298

Allows user to check if a game command has already been added

Parameters​

ParameterTypeDescription

name

string

The name of the command that is being checked

Returns​

boolean

true if found


isUsingSpeakerSeparation()​

isUsingSpeakerSeparation(): boolean | null;

Defined in: AACVoiceAPI.ts:335

Tells the user if speaker separation toggle is on

Returns​

boolean | null

The current status of whether speaker separation is on or off


removeVoiceCommand()​

removeVoiceCommand(name): boolean;

Defined in: AACVoiceAPI.ts:288

Allows user to remove a command from the system

Parameters​

ParameterTypeDescription

name

string

The name of the command that is to be removed from the list

Returns​

boolean

true if successfully removed


start()​

start(): void;

Defined in: AACVoiceAPI.ts:212

Allows the user to start speaking into the microphone and initiate game commands

Returns​

void


stop()​

stop(): void;

Defined in: AACVoiceAPI.ts:224

Stops all voice recording and transcription

Returns​

void


switchSpeakerMode()​

switchSpeakerMode(useSpeakerSeparation): void;

Defined in: AACVoiceAPI.ts:164

Switches between single speaker and multi-speaker mode for online mode Automatically restarts listening if currently active

Parameters​

ParameterTypeDescription

useSpeakerSeparation

boolean

Whether to use speaker separation

Returns​

void

Throws​

If not in online mode or not initialized

Example​

// Switch to multi speaker
api.switchSpeakerMode(true);

// Switch back to single speaker
api.switchSpeakerMode(false);

toggleSpeakerMode()​

toggleSpeakerMode(): void;

Defined in: AACVoiceAPI.ts:195

Returns​

void