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

    Class MoonshineModel

    Implements speech-to-text inferences with Moonshine models.

    Index

    Constructors

    • Create (but do not load) a new MoonshineModel for inference.

      Parameters

      • modelURL: string

        A string (relative to Settings.BASE_ASSET_PATH) where the .onnx model weights are located.

      • precision: string = "quantized"

      Returns MoonshineModel

      Creating a MoonshineModel has the side effect of setting the path to the onnxruntime-web .wasm to the Settings.BASE_ASSET_PATH

    Methods

    • Tests the inference latency of the current environment.

      Parameters

      • sampleSize: number = 10

        (Optional) The number of samples to use for computing the benchmark

      Returns Promise<number>

      The average inference latency (in ms) over the number of samples taken.

      Warning: since this uses noise to benchmark the model, the model will have lower performance if you to use it for transcription immediately after benchmarking.

    • Generate a transcription of the passed audio.

      Parameters

      • audio: Float32Array

        A Float32Array containing raw audio samples from an audio source (e.g., a wav file, or a user's microphone)

      Returns Promise<string>

      A Promise<string> that resolves with the generated transcription.

    • Returns whether or not the model weights have been loaded.

      Returns boolean

      true if the model is loaded, false if not.

    • Returns whether or not the model is in the process of loading.

      Returns boolean

      true if the model is currently loading, false if not.

    • Load the model weights.

      Returns Promise<void>

      This can be a somewhat long-running (in the tens of seconds) async operation, depending on the user's connection and your choice of model (tiny vs base). To avoid weird async problems that can occur with multiple calls to loadModel, we store and return a single Promise that resolves when the model is loaded.