Getting Started
You can use Moonshine.js via CDN, or you can install it with npm
. Simply import the package depending on your preferred method.
Via CDN
import * as Moonshine from 'https://cdn.jsdelivr.net/npm/@usefulsensors/moonshine-js@latest/dist/moonshine.min.js'
Via npm
Install the package first:
npm install @usefulsensors/moonshine-js
Then import:
import * as Moonshine from '@usefulsensors/moonshine-js'
Quickstart
Let’s get started with a simple example. We’ll create a transcriber to print speech from the microphone to the console. We can use the MicrophoneTranscriber for that. You can control the behavior of the transcriber by passing it a set of callbacks when you create it:
import * as Moonshine from 'https://cdn.jsdelivr.net/npm/@usefulsensors/moonshine-js@latest/dist/moonshine.min.js'
var transcriber = new Moonshine.MicrophoneTranscriber(
"model/tiny", // the fastest and smallest Moonshine model
{
onTranscriptionUpdated(text) {
console.log(text)
}
}
)
transcriber.start();
When we start the transcriber, the browser will request mic permissions and begin printing everything the user says to the console. It is useful in some cases to wait until the user has stopped speaking to transcribe their words. In this case, we’ll enable voice activity detection (VAD) when we create the transcriber:
var transcriber = new Moonshine.MicrophoneTranscriber(
"model/tiny",
{
onTranscriptionUpdated(text) {
console.log(text)
}
},
true // enable voice activity detection
)
transcriber.start();
Now the transcription will only update between pauses in speech.
That’s all it takes to get started! Read the guides to learn how to transcribe audio from other sources, or to build voice-controlled applications.