Microphones

We can use the MicrophoneTranscriber to transcribe audio from a user’s microphone. You can control the behavior of the transcriber by passing it callbacks when you create it:

var transcriber = new Moonshine.MicrophoneTranscriber(
    "model/tiny", // the fastest and smallest Moonshine model
    {
        onTranscriptionCommitted(text) {
            console.log(text)
        }
    }
)

transcriber.start();

When we start the transcriber, the browser will request mic permissions and print “commits” of the transcript to the console via the onTranscriptionCommitted callback. A commit is a continuous chunk of speech without pauses. For example, if you say: “Hello world, how are you?” and then stop speaking, the commit should be the full phrase. Try it out:

Start
Press start to try microphone transcription.

Streaming Mode

MoonshineJS also supports a streaming mode that continually updates the transcript between commits. To get the content of updates, you add a new callback called onTranscriptionUpdated.

In this case, if you say the phrase “Hello world, how are you?”, you might expect a sequence of updates [“Hello”, “Hello, world”, “Hello world, how”, “Hello world, how are”] before the commit “Hello world, how are you?”. To enable streaming mode, specify the onTranscriptionUpdated callback and set useVAD (the third argument) to false:

var transcriber = new Moonshine.MicrophoneTranscriber(
    "model/tiny",
    {
        onTranscriptionCommitted(text) {
            console.log(`Commit: ${text}`)
        }
        onTranscriptionUpdated(text) {
            console.log(`Update: ${text}`)
        }
    },
    false // disable VAD (use streaming mode)
)

transcriber.start();

Now the transcription will continually update between commits. Try it out to see the difference:

Start
Press start to try microphone transcription in streaming mode.