Canonical AI
Analytics service for processing and analyzing conversation recordings using Canonical AI’s Voice API
Overview
CanonicalMetricsService
processes conversation audio and uploads it to Canonical Voice API for analysis. It works in conjunction with an AudioBufferProcessor
to capture and process the conversation audio.
Installation
To use CanonicalMetricsService
, install the required dependencies:
You’ll also need to set up your Canonical API key as an environment variable: CANONICAL_API_KEY
You can obtain a Daily API key by signing up at Canonical AI.
Configuration
Constructor Parameters
HTTP client session for API communication
Processor instance for handling audio buffers
Unique identifier for the call, used to match calls in Canonical Voice system
Identifier for the AI assistant, used for grouping and distinguishing between different assistants
Canonical Voice API key
Canonical Voice API endpoint
Indicates if the assistant speaks first in the conversation
Directory to save temporary audio files
Usage Example
File Management
The service manages audio files in the following way:
- Creates temporary WAV files in the specified output directory
- Uses multipart upload for efficient file transfer
- Automatically cleans up temporary files after successful upload
File Naming Convention
Upload Process
The service uses a three-step upload process:
-
Request Upload
- Requests presigned URLs for multipart upload
- Calculates required parts based on file size
-
Upload Parts
- Splits file into 5MB chunks
- Uploads each part using presigned URLs
- Collects ETags for verification
-
Complete Upload
- Finalizes the upload
- Associates recording with call and assistant metadata
Frame Flow
Error Handling
The service includes comprehensive error handling:
- Validates API responses
- Handles upload failures
- Manages temporary file cleanup
- Reports errors through logging
Notes
- Requires sufficient disk space for temporary files
- Uses multipart upload for files larger than 5MB
- Automatically manages temporary file cleanup
- Supports conversation analysis and metrics
- Handles both assistant and user audio
- Includes metadata about conversation flow