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

index.html
<!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

  • ZerothBase

    • Basic functions for connecting with Zeroth API and sending data

    • Audio capture functions not included.

  • ZerothMic

    • Extension of ZerothBase for using browser's microphone recording function.

    • Easily enable real-time STT (i.e. transcriptions as the user is talking).

  • ZerothFile

    • 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:

CDN is not supported for alpha version. Please download zeroth.min.js from here

ES5 - UMD Build

Get Access Token

You should add one API endpoint in your server to get accessToken. Please check this page.

REST API

Create 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.

⚠️ important you have to replace$YOUR_APP_ID and$YOUR_APP_SECRETwith yours from Zeroth Console. You will have to create new application.

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)

⚠️ important you have to replace $YOUR_ACCESS_TOKEN with access_token what you got from here

Using without Server

Link (Get Access Token > Using without Server)

⚠️ important you have to replace$YOUR_APP_ID and$YOUR_APP_SECRETwith yours from Zeroth Console. You will have to create new application.

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.

⚠️ important you have to replace$YOUR_APP_ID and$YOUR_APP_SECRETwith yours from Zeroth Console. You will have to create new application.

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:

  • onconnect

    • Upon successful connection to Zeroth

    • Add "start audio recording" or "prepare to send audio file" logic in here.

  • ondata

    • Upon getting a result from Zeroth

    • You can get the full JSON result and add logic related to the result here.

  • ondisconnect

    • Upon disconnecting from Zeroth.

    • Add "stop recording" logic in here.

  • onerror

    • When 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.

⚠️ important you have to replace$YOUR_APP_ID and$YOUR_APP_SECRETwith yours from Zeroth Console. You will have to create new application.

Last updated