UNPKG

sofya.transcription

Version:

a JavaScript library that provides a robust and flexible solution for real-time audio transcription. It is designed to transcribe audio streams and can be easily integrated into web applications.

82 lines (68 loc) 2.43 kB
// @ts-nocheck import { SpeechRecognizer } from 'microsoft-cognitiveservices-speech-sdk'; import { EventEmitter } from 'events'; import { ITranscriptionConfig } from './ITranscriptionService'; export interface ITranscriptionService extends EventEmitter { initialize(mediaStream: MediaStream): void; startTranscription(): void; stopTranscription(): void; } export class SofyaTranscriber extends EventEmitter implements ITranscriptionService { /** * Initializes a new instance of the SofyaTranscriber class. * @param apiKey The API key required for authentication with the transcription service. * @param config An object with transcription configuration (e.g., language, model, region). */ constructor(apiKey: string, config: ITranscriptionConfig); /** * Starts the transcription process. This method listens for recognizing, recognized, and other relevant events. * @param mediaStream The MediaStream to be used for transcription. * Throws an error if the recognizer has not been initialized. */ startTranscription(mediaStream: MediaStream): void; /** * Stops the ongoing transcription process. */ stopTranscription(): void; /** * Pauses the ongoing transcription process. */ pauseTranscription(): void; /** * Resumes the ongoing transcription process. */ resumeTranscription(): void; /** * Event emitted when speech is being recognized. * @event recognizing * @param text The text that is currently being recognized. */ on(event: 'recognizing', listener: (text: string) => void): this; /** * Event emitted when speech is successfully recognized. * @event recognized * @param text The recognized text. */ on(event: 'recognized', listener: (text: string) => void): this; /** * Event emitted when no match is found for the recognized speech. * @event nomatch */ on(event: 'nomatch', listener: () => void): this; /** * Event emitted when an error occurs during the transcription process. * @event error * @param error The error details. */ on(event: 'error', listener: (error: any) => void): this; /** * Event emitted when an the transcription service is ready to start. * @event ready */ on(event: 'ready', listener: () => void): this; /** * Event emitted when the transcription session stops. * @event stopped */ on(event: 'stopped', listener: () => void): this; }