OMD Documentation

omdTranscriptionService

The omdTranscriptionService class provides an interface to an AI-powered transcription service for handwritten content. It sends image data to a server-side endpoint for processing, abstracting away the complexities of AI model interaction and API key management.

Class Definition

export class omdTranscriptionService

Constructor

new omdTranscriptionService([options])

Creates a new omdTranscriptionService instance.

Public Properties

Public Methods

async transcribe(imageBlob, [options])

Transcribes an image containing handwritten content by sending it to the configured server endpoint. The image is converted to base64 before transmission.

async transcribeWithFallback(imageBlob, [options])

Transcribes an image with a fallback mechanism. Currently, this method simply calls transcribe(), but it is designed to allow for future implementations of fallback transcription providers or strategies.

isAvailable()

Checks if the transcription service is available. In the current implementation, this always returns true as it relies on a serverless function endpoint.

getAvailableProviders()

Gets the list of available transcription providers. In the current implementation, this always returns ['gemini'] as the server handles the actual provider selection.

isProviderAvailable(provider)

Checks if a specific transcription provider is available. In the current implementation, this only returns true for the 'gemini' provider.

Internal Methods

Example Usage

import { omdTranscriptionService } from '@teachinglab/omd';

// Create a transcription service instance
const transcriptionService = new omdTranscriptionService();

// Assume getMyImageBlob() is a function that returns an image Blob
async function getMyImageBlob() {
    // Example: Create a dummy canvas and get its blob
    const canvas = document.createElement('canvas');
    canvas.width = 100; canvas.height = 50;
    const ctx = canvas.getContext('2d');
    ctx.fillText('2x + 3', 10, 30);
    return new Promise(resolve => canvas.toBlob(resolve, 'image/png'));
}

// Get an image blob from a canvas or file input
const imageBlob = await getMyImageBlob();

// Transcribe the image
const result = await transcriptionService.transcribe(imageBlob, {
    prompt: 'Transcribe the handwritten math equation. Return only the mathematical expression.'
});

console.log(result.text); // The transcribed text (e.g., "2x + 3")
↑ Top