Skip to content

@ariontalk/core

@ariontalk/core holds what both engines share: the engine interface and types, page understanding, highlights and utilities. It has no engine implementation and no UI. The engines live in @ariontalk/engine-local (on-device) and @ariontalk/engine-gemini (cloud).

Installation

Terminal window
pnpm add @ariontalk/core

Types

VoiceEngineInterface

The contract every engine must implement. Both VoiceEngine from @ariontalk/engine-local and GeminiEngine from @ariontalk/engine-gemini conform to this interface.

interface VoiceEngineInterface {
// Lifecycle
startSession(lang: string): Promise<void>;
endSession(): void;
destroy(): void;
// Runtime
switchLanguage(lang: string): void;
setMuted(muted: boolean): void;
// Voice settings
applyVoiceSettings(settings: VoiceSettings): void;
getVoiceOverrides(): VoiceSettings | null;
getVoices(): VoiceInfo[];
// State
readonly state: VoiceEngineState;
onStateChange: ((state: VoiceEngineState) => void) | null;
// Capabilities (engines declare what they support)
readonly capabilities: EngineCapabilities;
}

VoiceEngineState

Reactive state snapshot emitted via onStateChange.

interface VoiceEngineState {
status: EngineStatus;
currentLang: SupportedLang;
elapsedSeconds: number;
interimTranscript: string;
error: string | null;
downloadProgress: number;
}

EngineStatus

Union of all possible engine statuses.

type EngineStatus = 'idle' | 'loading' | 'listening' | 'thinking' | 'speaking' | 'error';

EngineCapabilities

Declares what an engine supports so the UI can adapt.

interface EngineCapabilities {
supportedLanguages: readonly string[];
supportsVoiceSelection: boolean;
supportsRatePitchVolume: boolean;
supportsBargeInPlugins: boolean;
supportsOffline: boolean;
maxSessionDurationSec: number | null; // null = unlimited
requiresTokenServer: boolean;
}

VoiceSettings

User-configurable voice parameters persisted across sessions.

interface VoiceSettings {
voiceId: string | null;
rate: number;
pitch: number;
volume: number;
}

VoiceInfo

Describes a single voice available for synthesis.

interface VoiceInfo {
id: string; // Unique identifier (voiceURI for local, name for Gemini)
name: string; // Display name
lang: string; // BCP-47 language code
local: boolean; // True for on-device voices
}

SupportedLang / WellKnownLang

Language code types. WellKnownLang enumerates known codes; SupportedLang also accepts arbitrary BCP-47 strings.

type WellKnownLang = 'en' | 'es' | 'ja' | 'fr' | 'de' | 'pt'
| 'it' | 'zh' | 'ko' | 'hi' | 'ar' | 'ru';
type SupportedLang = WellKnownLang | (string & {});

BargeInDetector

Plugin interface for barge-in (interruption) detection strategies.

interface BargeInDetector {
/** Acquire resources (mic stream, models, etc.). Called once per session. */
init(): Promise<void>;
/** Start monitoring. Call onBargeIn once when interruption is detected. */
startMonitoring(onBargeIn: () => void): void;
/** Stop monitoring without releasing resources. */
stopMonitoring(): void;
/** Release all resources. Called when the engine is destroyed. */
destroy(): void;
}

ImageContext

Metadata for images extracted from the host page and sent to the AI model.

interface ImageContext {
blob: Blob;
alt: string;
src: string;
}

Services

These lower-level services are exported for advanced consumers who want to compose their own engine or extend individual capabilities.

ServiceDescription
PageExtractorServiceExtracts visible text and image context from the host page for use as AI grounding context.
PageIndexerServiceAssigns stable IDs to page sections and images (sec-1, img-2) so the model can reference them for highlights.
HighlightManagerScrolls to and highlights elements on the host page. Shared by both engines.
EnergyBargeInDetectorA BargeInDetector that uses microphone energy levels to detect when the user speaks during playback.

The on-device speech and Prompt API services (SpeechRecognitionService, SpeechSynthesisService, AISessionService) are in @ariontalk/engine-local.

Utilities

isVoiceChatSupported(engine?)

Async function that checks whether all required browser APIs are available.

import { isVoiceChatSupported } from '@ariontalk/core';
const ok = await isVoiceChatSupported(); // checks local engine APIs
const ok = await isVoiceChatSupported('gemini'); // checks Gemini engine APIs

Checks performed:

EngineRequired APIs
'local' (default)SpeechRecognition, speechSynthesis, LanguageModel (Prompt API) with model availability
'gemini'navigator.mediaDevices.getUserMedia, AudioContext

Returns true if all required APIs are present and functional, false otherwise.

SessionTimer

Tracks elapsed session time in seconds. Accepts a callback that fires every second with the current count. Provides start(), reset(), and the static SessionTimer.format(seconds) helper to produce MM:SS display strings.

createLogger(scope) / setLogLevel(level) / LogLevel

Scoped, level-gated console logging.

import { createLogger, setLogLevel, LogLevel } from '@ariontalk/core';
setLogLevel(LogLevel.Debug); // Enable all logs globally
const log = createLogger('my-mod'); // Prefixed as [ariontalk:my-mod]
log.debug('verbose info');
log.info('general info');
log.warn('warning');
log.error('error');

LogLevel enum:

enum LogLevel {
Disabled = 'disabled',
Errors = 'error',
Warnings = 'warning',
Info = 'info',
Debug = 'debug',
}

setLogLevel updates every logger created via createLogger, both past and future.