Microphones
We can use the MicrophoneTranscriber class to transcribe audio from a user’s microphone. 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. Try it out:
Start
Press start to try microphone transcription.
Voice Activity Detection
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. Try it out to see the difference:
Start
Press start to try microphone transcription with VAD enabled.