Skip to main content

Services

Service classes for AI chat, text-to-speech, speech-to-text, translation, summarization, rewriting, and content generation.

AIService

Multi-provider AI service with unified interface for Chrome AI, OpenAI, and Ollama.

Methods

function
Configure AI client with provider settings.Parameters:
  • config: Configuration object
  • config.provider: ‘chrome-ai’ | ‘openai’ | ‘ollama’
  • config.chromeAi: Chrome AI settings (temperature, topK, enableImageSupport, enableAudioSupport)
  • config.openai: OpenAI settings (apiKey, model, temperature, maxTokens)
  • config.ollama: Ollama settings (endpoint, model, temperature, maxTokens)
  • tabId: Tab ID (extension mode only)
Returns: Success status
function
Check if service is configured and ready.
function
Stream chat completion responses.Parameters:
  • messages: Array of message objects with role and content
  • options: { systemPrompt?, temperature?, maxTokens?, images?, audios? }
  • tabId: Tab ID (extension mode only)
Yields: Text chunks as they arriveExample:
function
Abort ongoing chat request.

Supported Providers

  • On-device inference (no API key required)
  • Multi-modal: Images and audio support
  • Requirements: Chrome 138+ with flags enabled
  • Model: Gemini Nano (2B-4B parameters)
  • Cloud-based (API key required)
  • Models: GPT-4, GPT-4 Turbo, GPT-4o, GPT-3.5 Turbo
  • Multi-modal: Images support (GPT-4 Vision)
  • Audio: Via Whisper transcription
  • Self-hosted (local server)
  • Models: Llama 2, Mistral, Mixtral, etc.
  • Multi-modal: Depends on model (LLaVA for images)
  • Endpoint: Default http://localhost:11434

TTSService

Multi-provider Text-to-Speech service with streaming generation and audio queue management.

Methods

function
Configure TTS client with provider settings.Parameters:
  • config.provider: ‘kokoro’ | ‘openai’ | ‘openai-compatible’
  • config.kokoro: Kokoro settings (modelId, voice, speed, device)
  • config.openai: OpenAI TTS settings (apiKey, model, voice, speed)
  • config['openai-compatible']: Generic TTS API settings
  • tabId: Tab ID (extension mode only)
function
Check if service is configured and ready.
function
Generate TTS audio with intelligent text chunking.Parameters:
  • text: Text to synthesize
  • voice: Voice ID (overrides config)
  • chunkSize: Target chunk size in characters (default: 500)
  • minChunkSize: Minimum chunk size (default: 100)
  • sessionId: Session identifier for tracking
  • tabId: Tab ID (extension mode only)
Returns: Array of audio blob URLs
function
Play sequence of audio chunks with queue management.Parameters:
  • audioBlobUrls: Array of blob URLs to play
  • sessionId: Session identifier
function
Stop current TTS playback and clear queue.
function
Initialize lip-sync animation converter with Babylon.js scene.
function
Set callback for triggering speak animations with lip sync.

Supported Providers

  • On-device synthesis using ONNX runtime
  • Voices: 30+ high-quality neural voices
  • Backends: WebGPU (fast) or WASM (compatible)
  • Languages: English, Japanese, Chinese, Korean, French, Spanish
  • Lip Sync: Automatic BVMD generation for 3D character
  • Cloud-based (API key required)
  • Models: tts-1 (fast), tts-1-hd (high quality)
  • Voices: alloy, echo, fable, onyx, nova, shimmer
  • Speed: Adjustable 0.25x to 4.0x
  • Generic TTS API (Cartesia, ElevenLabs, etc.)
  • Custom endpoint and voice configuration
  • OpenAI SDK compatibility

STTService

Multi-provider Speech-to-Text service supporting one-shot transcription and continuous streaming.

Methods

function
Configure STT client with provider settings.Parameters:
  • config.provider: ‘chrome-ai-multimodal’ | ‘openai’ | ‘openai-compatible’
  • config['chrome-ai-multimodal']: Chrome AI settings
  • config.openai: OpenAI Whisper settings
  • config['openai-compatible']: Generic STT API settings
function
Check if service is configured.
function
Start recording audio from microphone.Returns: Success status
function
Stop recording and transcribe audio.
function
Set callback for transcription results.
function
Set callback for error handling.

TranslatorService

Multi-provider translation service with support for Chrome AI Translator API and LLM-based translation.

Methods

function
Configure translator with provider settings.Parameters:
  • config.provider: ‘chrome-ai’ | ‘openai’ | ‘ollama’
function
Stream translation results.Parameters:
  • text: Text to translate
  • sourceLang: Source language code (e.g., ‘en’)
  • targetLang: Target language code (e.g., ‘es’)
  • tabId: Tab ID (extension mode only)
Yields: Translated text chunks
function
Check if language pair is available for translation.
function
Abort ongoing translation request.

SummarizerService

Multi-provider text summarization service supporting Chrome AI Summarizer API and LLM-based summarization.

Methods

function
Configure summarizer with provider settings.
function
Stream summarization results.Parameters:
  • text: Text to summarize
  • options.type: ‘tldr’ | ‘headline’ | ‘key-points’ | ‘teaser’
  • options.format: ‘plain-text’ | ‘markdown’
  • options.length: ‘short’ | ‘medium’ | ‘long’
  • tabId: Tab ID (extension mode only)
Yields: Summary text chunks
function
Check if summarization is available.
function
Abort ongoing summarization request.

RewriterService

Multi-provider text rewriting service with tone, format, and length adjustments.

Methods

function
Configure rewriter with provider settings.
function
Stream rewriting results.Parameters:
  • text: Text to rewrite
  • options.tone: ‘as-is’ | ‘more-formal’ | ‘more-casual’ | ‘professional’ | ‘friendly’
  • options.format: ‘as-is’ | ‘plain-text’ | ‘markdown’
  • options.length: ‘as-is’ | ‘shorter’ | ‘longer’
  • options.context: Additional context for rewriting
  • tabId: Tab ID (extension mode only)
Yields: Rewritten text chunks
function
Abort ongoing rewrite request.

WriterService

Multi-provider content generation service for creating new text from prompts.

Methods

function
Configure writer with provider settings.
function
Stream content generation results.Parameters:
  • prompt: Writing prompt
  • options.tone: ‘neutral’ | ‘formal’ | ‘casual’ | ‘professional’ | ‘friendly’
  • options.format: ‘plain-text’ | ‘markdown’
  • options.length: ‘short’ | ‘medium’ | ‘long’
  • options.context: Additional context
  • tabId: Tab ID (extension mode only)
Yields: Generated text chunks
function
Abort ongoing write request.

ChatHistoryService

Service for managing persistent chat history with message trees and media storage.

Methods

function
Save a chat with all associated data.Parameters:
  • chatData.chatId: Chat ID (auto-generated if not provided)
  • chatData.chatService: ChatService instance (for tree structure)
  • chatData.messages: Flat message array (backward compatibility)
  • chatData.title: Chat title (auto-generated if not provided)
  • chatData.isTemp: Skip saving if true
  • chatData.metadata: Additional metadata
Returns: Chat ID
function
Load a chat with all data and media.Returns: Chat record with messages and metadata
function
List saved chats with pagination.Parameters:
  • offset: Skip first N chats (default: 0)
  • limit: Max chats to return (default: 20)
Returns: Array of chat records (sorted by updatedAt descending)
function
Delete a chat and all associated media.
function
Update the title of a saved chat.
function
Search chats by title or content.

Usage Examples