Web Library Introduction
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 API Reference page.
See 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 the example.html and open the 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-voice.js"></script>
2. Transcribe
The code creates the RecordTranscribe object, which simultaneously (1) captures the audio from your microphone, (2) transcribes the audio using Soniox speech recognition service, and (3) prints recognized words into web console.
Make sure to set your API key, which you can find under API Keys tab for a given project in Soniox Console.
<script>
// Set your API key.
let apikey = "<YOUR-API-KEY>";
// Create RecordTranscribe object.
let recordTranscribe = new sonioxWebVoice.RecordTranscribe()
// Set event handler.
recordTranscribe.setOnPartialResult(printWords)
function printWords(result) {
for (let i = 0; i < result.words.length; ++i) {
console.log(result.words[i]);
}
}
// Start transcribing from your microphone.
recordTranscribe.start()
</script>