Skip to main content

SpeechConverterOffline

aac-voice-api


Defined in: SpeechConverterOffline.ts:12

SpeechConverter handles real-time speech-to-text conversion using the Whisper model. It manages audio input, preprocessing, and transcription directly in the browser.

Implements​

Constructors​

Constructor​

new SpeechConverterOffline(): SpeechConverterOffline;

Defined in: SpeechConverterOffline.ts:23

Returns​

SpeechConverterOffline

Methods​

getStatus()​

getStatus(): string;

Defined in: SpeechConverterOffline.ts:306

Retrieves the current status of the Whisper model.

Returns "loading" if the model has not been initialized yet, otherwise returns the status string provided by the Whisper backend.

Returns​

string

  • The current operational status of the Whisper module.

Implementation of​

SpeechConverterInterface.getStatus


getTextLog()​

getTextLog(): string[];

Defined in: SpeechConverterOffline.ts:287

Returns​

string[]

Implementation of​

SpeechConverterInterface.getTextLog


getTranscribed()​

getTranscribed(): string;

Defined in: SpeechConverterOffline.ts:241

Retrieves the latest transcription result from the Whisper model and logs it.

This method calls the underlying Whisper API to obtain the most recently transcribed text. If any text has been returned from whisper, it logs it.

Returns​

string

  • The transcribed text from the current audio chunk.

Throws​

Throws if the Whisper module has not been initialized.

Implementation of​

SpeechConverterInterface.getTranscribed


init()​

init(modelPath, lang): Promise`<void>`;

Defined in: SpeechConverterOffline.ts:66

Initializes the Whisper module with the specified model and language.

This method:

  1. Creates the Whisper instance asynchronously.
  2. Loads the model file into the in-memory filesystem.
  3. Initializes Whisper with the model path and language code.

Parameters​

ParameterTypeDescription

modelPath

string

Path or URL to the Whisper model file.

lang

string

Language code (e.g., 'en') to configure the model.

Returns​

Promise<void>

  • Resolves when the Whisper module is fully initialized.

Implementation of​

SpeechConverterInterface.init


startListening()​

startListening(): void;

Defined in: SpeechConverterOffline.ts:152

Starts listening to the user's microphone input, collects audio chunks, and feeds them into the Whisper model for transcription in real time.

The method continuously gathers small chunks from AudioInputHandler, combines them into fixed-size blocks, downsamples them to 16kHz (required by Whisper), and sends them to the model for inference.

Returns​

void

Throws​

Throws if init() was not called before invoking this method.

Implementation of​

SpeechConverterInterface.startListening


stopListening()​

stopListening(): void;

Defined in: SpeechConverterOffline.ts:206

Stops the audio input stream and halts the real-time transcription process.

This should be called after startListening() to stop capturing microphone input and free up system audio resources.

Returns​

void

Throws​

Throws if the Whisper module has not been initialized.

Implementation of​

SpeechConverterInterface.stopListening