API
Microphone Transcriber

undefined

Class: MicrophoneTranscriber

Defined in: microphoneTranscriber.ts:8

Accesses the user’s microphone and transcribes their speech.

Extends

Constructors

new MicrophoneTranscriber()

new MicrophoneTranscriber(
   modelURL, 
   callbacks, 
   useVAD): MicrophoneTranscriber

Defined in: microphoneTranscriber.ts:47

Creates a transcriber for transcribing an audio stream from a mic.

Parameters

Parameter Type Default value
modelURL string undefined
callbacks Partial<TranscriberCallbacks> {}
useVAD boolean false

Returns

MicrophoneTranscriber

Example

This basic example demonstrates the use of the transcriber with custom callbacks:

import MicrophoneTranscriber from "@usefulsensors/moonshine-js";

var transcriber = new MicrophoneTranscriber(
     "model/tiny"
     {
         onModelLoadStarted() {
             console.log("onModelLoadStarted()");
         },
         onTranscribeStarted() {
             console.log("onTranscribeStarted()");
         },
         onTranscribeStopped() {
             console.log("onTranscribeStopped()");
         },
         onTranscriptionUpdated(text: string | undefined) {
             console.log(
                 "onTranscriptionUpdated(" + text + ")"
             );
         },
         onTranscriptionCommitted(text: string | undefined) {
             console.log(
                 "onTranscriptionCommitted(" + text + ")"
             );
         },
     },
);

transcriber.start();

Overrides

StreamTranscriber.constructor

Properties

Property Modifier Type Default value Inherited from Defined in
audioContext protected AudioContext undefined StreamTranscriber.audioContext streamTranscriber.ts:14
callbacks public TranscriberCallbacks undefined StreamTranscriber.callbacks transcriber.ts:81
isActive public boolean false StreamTranscriber.isActive streamTranscriber.ts:18
mediaRecorder protected MediaRecorder undefined StreamTranscriber.mediaRecorder streamTranscriber.ts:13
model static MoonshineModel undefined StreamTranscriber.model transcriber.ts:80

Methods

attachStream()

attachStream(stream): void

Defined in: streamTranscriber.ts:116

Attaches a MediaStream to this StreamTranscriber for transcription. A MediaStream must be attached before starting transcription.

Parameters

Parameter Type Description
stream MediaStream A MediaStream to transcribe

Returns

void

Inherited from

StreamTranscriber.attachStream


detachStream()

detachStream(): void

Defined in: streamTranscriber.ts:129

Detaches the MediaStream used for transcription.

Returns

void

Inherited from

StreamTranscriber.detachStream


getAudioBuffer()

getAudioBuffer(): AudioBuffer

Defined in: streamTranscriber.ts:143

Returns the most recent AudioBuffer that was input to the underlying model for text generation. This is useful in cases where we want to double-check the audio being input to the model while debugging.

Returns

AudioBuffer

An AudioBuffer

Inherited from

StreamTranscriber.getAudioBuffer


loadModel()

loadModel(): Promise<void>

Defined in: transcriber.ts:93

Returns

Promise<void>

Inherited from

StreamTranscriber.loadModel


start()

start(): Promise<void>

Defined in: microphoneTranscriber.ts:66

Starts transcription.

This will request microphone permissions (if not already provided), load the model (if not already loaded), and do one of the following:

if useVAD === true: generate an updated transcription at the end of every chunk of detected voice activity. else if useVAD === false: generate an updated transcription every Settings.FRAME_SIZE milliseconds.

Transcription will stop when stop is called, or when Settings.MAX_RECORD_MS is passed (whichever comes first).

Returns

Promise<void>

Overrides

StreamTranscriber.start


stop()

stop(): void

Defined in: streamTranscriber.ts:257

Stops transcription.

Returns

void

Inherited from

StreamTranscriber.stop