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.
The URL that the underlying MoonshineModel weights should be loaded from, relative to Settings.BASE_ASSET_PATH.MOONSHINE.
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.
A boolean specifying whether or not to use Voice Activity Detection (VAD) for deciding when to perform transcriptions.
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.
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();
Attaches a MediaStream to this Transcriber for transcription. A MediaStream must be attached before starting transcription.
A MediaStream to transcribe
Detaches the MediaStream used for transcription. TODO
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.
An AudioBuffer
Preloads the models and initializes the buffer required for transcription.
Starts transcription.
Transcription will stop when stop is called.
Note that the Transcriber must have a MediaStream attached via Transcriber.attachStream before starting transcription.
Stops transcription.
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