@moonshine-ai/moonshine-js
    Preparing search index...

    Class MicrophoneTranscriber

    Accesses the user's microphone and transcribes their speech.

    Hierarchy (View Summary)

    Index

    Constructors

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

      Parameters

      • modelURL: string
      • callbacks: Partial<TranscriberCallbacks> = {}
      • useVAD: boolean = true
      • precision: string = "quantized"

      Returns MicrophoneTranscriber

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

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

      var transcriber = new MicrophoneTranscriber(
      "model/tiny"
      {
      onPermissionsRequested() {
      console.log("Requesting permissions.")
      },
      onError(error) {
      console.log(`Error: ${error}`)
      },
      onModelLoadStarted() {
      console.log("onModelLoadStarted()");
      },
      onTranscribeStarted() {
      console.log("onTranscribeStarted()");
      },
      onTranscribeStopped() {
      console.log("onTranscribeStopped()");
      },
      onTranscriptionUpdated(text: string) {
      console.log(
      "onTranscriptionUpdated(" + text + ")"
      );
      },
      onTranscriptionCommitted(text: string) {
      console.log(
      "onTranscriptionCommitted(" + text + ")"
      );
      },
      },
      false // use streaming mode
      );

      transcriber.start();

    Properties

    audioContext: AudioContext
    isActive: boolean = false

    Methods

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

      Parameters

      • stream: MediaStream

        A MediaStream to transcribe

      Returns void

    • 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.

      Parameters

      • buffer: Float32Array

      Returns AudioBuffer

      An AudioBuffer

    • Preloads the models and initializes the buffer required for transcription.

      Returns Promise<void>

    • Starts transcription. This will request permission to access the user's microphone, if it hasn't already been granted.

      Transcription will stop when stop is called.

      Returns Promise<void>