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

    Class Transcriber

    Implements real-time transcription of an audio stream sourced from a WebAudio-compliant MediaStream object.

    Read more about working with MediaStreams: https://developer.mozilla.org/en-US/docs/Web/API/MediaStream

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a transcriber for transcribing a MediaStream from any source. After creating the Transcriber, you must invoke Transcriber.attachStream to provide a MediaStream that you want to transcribe.

      Parameters

      • modelURL: string

        The URL that the underlying MoonshineModel weights should be loaded from, relative to Settings.BASE_ASSET_PATH.MOONSHINE.

      • callbacks: Partial<TranscriberCallbacks> = {}

        A set of TranscriberCallbacks used to trigger behavior at different steps of the transcription lifecycle. For transcription-only use cases, you should define the TranscriberCallbacks yourself; when using the transcriber for voice control, you should create a VoiceController and pass it in.

      • partialUpdates: boolean = true

        A boolean specifying whether to give partial transcriptions updates during speech. When set to true, the transcriber will only process speech at the end of each chunk of voice activity; when set to false, the transcriber will operate in streaming mode, generating continuous transcriptions on a rapid interval.

      • precision: string = "quantized"

      Returns Transcriber

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

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

      var transcriber = new Transcriber(
      "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 + ")"
      );
      },
      },
      false // use streaming mode
      );

      // Get a MediaStream from somewhere (user mic, active tab, an <audio> element, WebRTC source, etc.)
      ...

      transcriber.attachStream(stream);
      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

    • Detaches the MediaStream used for transcription. TODO

      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>