Skip to main content
Version: 0.0.16

SofyaTranscriber

The main class for handling transcription operations.

Constructor

new SofyaTranscriber(connection: Connection)

Creates a new instance of the transcription service with a connection object.

Methods

  • startTranscription(mediaStream: MediaStream): void Starts the transcription process with a given MediaStream.

  • stopTranscription(): Promise< void > Stops the transcription process asynchronously. Returns a Promise that resolves when cleanup is complete. You must use await or .then().

  • pauseTranscription(): void Pauses the transcription process.

  • resumeTranscription(): void Resumes the transcription process.

  • on(event: string, callback: Function): this Registers an event handler for transcription events.

  • getSttSessionId(): string | null Returns the identifier of the current STT connection. null until the first transcription message arrives, or against servers that don't send it.

  • getSttSessionIds(): string[] Returns every STT connection identifier for the current transcription, in order, since the last startTranscription() call. Resets on the next startTranscription().

Events

The SDK emits the following events:

  • recognizing: Fired when transcription is in progress.

  • recognized: Fired when transcription is complete.

  • error: Fired when an error occurs.

  • ready: Fired when the transcription service is ready to start.

  • stopped: Fired when the transcription process is stopped.

  • connected: Fired when the transcription service is connected to the provider.

  • stt_session: Fired when the server reports the identifier of the transcription connection — on the first transcription message, and again on every reconnection where the identifier changes.

    transcriber.on("stt_session", ({ sttSessionId, externalId, connectionAttempt }) => {
    // sttSessionId: connection UUID, assigned by the server
    // externalId: the configured external_id, or null
    // connectionAttempt: 1 on the first connection, 2 on the first reconnection…
    });
    • Fires once per connection: a session with two reconnections produces three events with three distinct ids.
    • Arrives with the first transcription message (it depends on audio), not on handshake. Nothing in the SDK waits for it.
    • Against a server that doesn't send the identifier, the event never fires and nothing else changes.
    • Receiving sttSessionId does not mean the session is being recorded. It identifies the connection; recording is controlled by record and the environment.

Types

SttSessionInfo

Payload of the stt_session event.

interface SttSessionInfo {
sttSessionId: string;
externalId: string | null;
connectionAttempt: number;
}