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.
122 lines (102 loc) • 3.26 kB
TypeScript
// @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(): Promise<void>;
pauseTranscription(): void;
resumeTranscription(): void;
}
export type SupportedLanguage = "pt-BR" | "en-US" | "es-ES";
export type Providers =
| "sofya_compliance"
| "oracle"
| "sofya_as_service"
| "sofya_whisper_flow"
| "stt_wvad";
// Base configuration interface with common properties
export interface BaseConfig {
language: SupportedLanguage;
}
export interface SofyaComplianceConfig extends BaseConfig {
token: string;
compartmentId: string;
region: string;
}
export interface SofyaSpeechConfig extends BaseConfig {}
export type Connection =
| { apiKey: string; config?: BaseConfig }
| {
provider: "sofya_compliance";
endpoint: string;
config: SofyaComplianceConfig;
}
| {
provider: "sofya_as_service";
endpoint: string;
config: SofyaSpeechConfig;
}
| { provider: "stt_wvad"; endpoint: string; config: SofyaSpeechConfig };
export class SofyaTranscriber
extends EventEmitter
implements ITranscriptionService
{
/**
* Initializes a new instance of the SofyaTranscriber class.
* @param connection The connection object required for authentication with the transcription service.
*/
constructor(connection: Connection);
/**
* 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(): Promise<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;
}