Web Library#

Soniox Web Voice is a Javascript client library that enables you to integrate with Soniox API service directly from your web application. In just a few lines of code, you can do real-time and low-latency automatic speech recognition with various configurations. See a complete example below.

For complete documentation of the Soniox Web Voice library, see the Web Library API Reference.

Source code of the library is available in the Soniox Web Voice GitHub repository.

Example#

This example demonstrates how to do live transcription from a microphone using Soniox Web Voice library in a webpage or a web application. It contains a simple user interface to start, stop or cancel live transcriptions from the microphone.

To try it out, download the example.html file, set your API key in example.html and open example.html in your browser.

Usage#

1. Include Javascript package#

Include Soniox Web Voice Javascript package in your HTML page. The package includes functionality for capturing audio from your microphone and communication with Soniox API service.

<script src="https://js.soniox.com/soniox-web-voice2.js"></script>

It is advised to load the module as above so that you are always using the latest version.

2. Transcribe#

The code creates the RecordTranscribe object, which simultaneously captures audio from your microphone and transcribes it using Soniox speech recognition service. Transcription results are returned to a callback function in the example, which simply prints recognized text into the developer console.

Make sure to set your API key, which you can find under API Keys tab for a given project in Soniox Console. To avoid exposing your regular API key to web clients, you can use Temporary API Keys.

<script>

// Set your API key.
let apikey = "<YOUR-API-KEY>";

// Create RecordTranscribe object and set options.
let recordTranscribe = new sonioxWebVoice.RecordTranscribe();
recordTranscribe.setApiKey(apikey);
recordTranscribe.setModel("en_v2_lowlatency");
recordTranscribe.setIncludeNonFinal(true);

// Set event handler.
recordTranscribe.setOnPartialResult(printResult)

function printResult(result) {
    let text = result.words.map((word) => word.text).join("");
    console.log(text);
}

// Start transcribing from your microphone.
recordTranscribe.start();

</script>