JavaScript Library
Before start
You can use Zeroth on any web browser that supports getUserMedia.
In this tutorial, we demonstrate how to use the zeroth-js library.
HTML File
<!DOCTYPE html>
<html>
<body>
<div>
<h2>Zeroth Demo</h2>
<h3>Record</h3>
<p>
<button class='start'>start</button>
<button class='stop'>stop</button>
</p>
<h3>Response</h3>
<p>
<span><b>transcript only - </b></span>
<span class='transcript'></span>
</p>
<p>
<span><b>complete json - </b></span>
<span class='json'></span>
</p>
</div>
<!-- Import zeroth-js here -->
<script src='app.js'></script>
</body>
</html>Importing zeroth-js
Basic functions for connecting with Zeroth API and sending data
Audio capture functions not included.
Extension of ZerothBase for using browser's microphone recording function.
Easily enable real-time STT (i.e. transcriptions as the user is talking).
Extension of ZerothBase with function for sending recorded audio files.
In this example we will demonstrate usage of ZerothMic.
NPM
Using this method, you can import zeroth-js as follows:
ES6
ES5 - CommonJS
CDN
Include the js file directly in your web app using a<script> tag.
Using this method, you can use zeroth-js as follows:
ES5 - UMD Build
Get Access Token
Using with Server (Secure way, Recommended)
You should add one API endpoint in your server to get accessToken. Please check this page.
REST APICreate GET endpoint named /get-token (whatever you want) in your server.
This endpoint will return response of our this REST API.
For example, If you are using node.js, express and axios , Your code will look like below.
That's all what you need in server side. and You should use accessToken parameter instead of appId, appSecret.
Using without Server (Less secure but simple way)
zeroth-js will issue accessToken based on your appId, appSecret in parameter.
Parameters
Using with Server
Link (Get Access Token > Using with Server)
Using without Server
Link (Get Access Token > Using without Server)
In this case, zeroth-js will issue accessToken based on your appId, appSecret
Difference between with server, without server
Only difference is using accessToken or using appId and appSecret in parameter.
But we recommend Using with Server way because of security issue.
Initialize Zeroth
Create an app.js file, and import zeroth-js into your directory.
After importing, initialize Zeroth and add the following parameters.
In this tutorial, We will using Using without Server way for convenience.
If you are using Using with Server way, please replace appId , appSecret parameters with accessToken parameter.
That's it! Create an app.js file to start recording.
App.js
Start recording
Now, you are ready to use Zeroth with the microphone in your browser. To start recording, just call the start() function.
These are Zeroth's event callbacks:
onconnectUpon successful connection to Zeroth
Add "start audio recording" or "prepare to send audio file" logic in here.
ondataUpon getting a result from Zeroth
You can get the full JSON result and add logic related to the result here.
ondisconnectUpon disconnecting from Zeroth.
Add "stop recording" logic in here.
onerrorWhen you couldn't connected with Zeroth, or there's some error between Zeroth.
Add error handling here.
Now, let's add logic. First, get elements from our html.
Create an onSuccess function to add event callbacks to Zeroth. We will use the onSuccess function when start() 's getUserMedia() is successful.
Learn more about getUserMedia() here.
Then, add onclickevent to call start() and stop()
Full Code example
That's it! You have now successfully made a speech-to-text web application.
You can find more examples here.
Last updated