[All posts](/en/blog/)

[Developer](/en/category/developer/)

June 24, 2021

10 min read

# Building Your Own Transcription Service Within a Video Call Web App

Learn how to add transcription within a live video call web app using the Web Speech API and the Agora Web SDK

Agora Superstar

Author

![Building Your Own Transcription Service Within a Video Call Web App](/_assets/assets/agoras-website-assets/images/66733073bceb8fbb76501c7c_building-your-own-transcription-service-agora.png)

[All posts](/en/blog/)

On this page

1. [Introduction](#df28)

2. [Prerequisites](#c2e9)

3. [Project Setup](#0f73)

4. [Adding Color](#6c07)

5. [Core Functionality (JS)](#1676)

6. [Adding Voice-to-Text Services](#fe99)

7. [Conclusion](#87cc)

8. [You did it!](#d1e5)

*This blog was written by * [*Akshat Gupta*](https://www.linkedin.com/in/akshatvg/) * an Agora Superstar. The Agora Superstar program empowers developers around the world to share their passion and technical expertise, and create innovative real-time communications apps and projects using Agora’s customizable SDKs.*

## Introduction

*Transcription* or *closed-captioning* has become a very common feature in most video conferencing applications.

This service is useful not only for people with impaired hearing but also for other situations. For example, transcribed text can be read when audio cannot be heard either because of a noisy environment (such as an airport) or because of an environment that must be kept quiet (such as a library).

For students, this service can be useful for taking notes. Especially when students are falling behind in class, the transcription feature can help students to catch up the progress.

Because of its benefits, several video calling giants have incorporated this feature into their applications, including Microsoft Teams, Google Meet, Zoom, and Skype.

In this tutorial, we will develop a web application that supports **speech-to-text transcription **using JavaScript’s [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API) , the [Agora Web SDK](https://docs.agora.io/en/Video/downloads?platform=Web) , and the [Agora RTM SDK](https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_web/v1.0.0/index.html) .

![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #1](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb0409_building-your-own-transcription-service-agora-1-1024x571.png)

Screenshot of the simple application we will be developing.

## Prerequisites

- Basic knowledge of how to work with JavaScript, JQuery, Bootstrap, and Font Awesome

- Agora account ( [How to Get Started with Agora](/en/blog/how-to-get-started-with-agora/) )

- Know how to use the [Agora Web SDK](https://docs.agora.io/en/Video/downloads?platform=Web) and the [Agora RTM SDK](https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_web/v1.0.0/index.html)

## Project Setup

Let’s start by laying out our basic HTML structure. A few UI elements are necessary, such as the local video stream, the remote video streams, buttons to join or leave the call, and buttons to start or stop recording the user's voice*. *I have added a few input fields for the App Id, channel name, and username above the `div` containing the video containers and the transcription output boxes. I’ve also imported the necessary CDNs and linked the custom CSS and JS files:

transcription.html

```
<!DOCTYPE html>
<html lang="en">


<head>


  <!-- Meta Tags -->
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Agora Transcription Demo</title>
  <link rel="icon" href="./favicon.png" type="image/png">
  <link rel="apple-touch-icon" href="./apple-touch-icon.png" type="image/png">


  <!-- CSS only -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
  <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
  <link rel="stylesheet" href="./transcription.css">


</head>


<body>


  <!-- Container -->
  <div class="container-fluid banner">
    <p class="banner-text">Agora Transcription Demo</p>
  </div>


  <div class="container mt-5 mb-5">
    <form id="join-form">
      <div class="row join-info-group">
        <div class="col-sm">
          <p class="join-info-text">AppID</p>
          <input id="appid" type="text" placeholder="Enter AppID" required class="form-control">
        </div>
        <div class="col-sm">
          <p class="join-info-text">Channel</p>
          <input id="channel" type="text" placeholder="Enter Channel Name" required class="form-control">
        </div>
        <div class="col-sm">
          <p class="join-info-text">Name</p>
          <input id="accountName" type="text" placeholder="Enter Your Name" required class="form-control">
        </div>
      </div>


      <div class="button-group mt-2">
        <button id="join" type="submit" class="btn btn-sm">Join</button>
        <button id="leave" type="button" class="btn btn-sm" disabled>Leave</button>
        <button id="transcribe" type="button" class="btn btn-sm" disabled>Start <i class="fa fa-bullhorn"></i></button>
        <button id="stop-transcribe" type="button" class="btn btn-sm" disabled>Stop <i
            class="fa fa-bullhorn"></i></button>
        <button id="note" type="button" class="btn btn-sm" disabled>Take <i class="fa fa-sticky-note"></i></button>
        <button id="stop-note" type="button" class="btn btn-sm" disabled>Stop <i class="fa fa-sticky-note"></i></button>
      </div>
    </form>


    <div class="row">
      <div class="col">
        <div class="row video-group">
          <div class="col">
            <p id="local-player-name" class="player-name"></p>
            <div id="local-player" class="player"></div>
          </div>
          <div class="w-100"></div>
          <div class="col">
            <div id="remote-playerlist"></div>
          </div>
        </div>
      </div>
      <div class="col">
        <div class="transcribed-text my-3">
          <h5 class="text-decoration-underline">Transcribed Text:</h5>
          <div class="actual-text" id="actual-text">
          </div>
        </div>
        <div class="transcribed-text my-3">
          <h5 class="text-decoration-underline">Notes:</h5>
          <div class="note-text" id="note-text">
          </div>
        </div>
      </div>
    </div>
  </div>


  <!-- Scripts -->
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"
    integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
    crossorigin="anonymous"></script>
  <script src="https://download.agora.io/sdk/release/AgoraRTC_N.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/agora-rtm-sdk@1.3.1/index.js"></script>
  <script src="./transcription.js"></script>
</body>


</html>
```

‍

![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #2](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb03db_building-your-own-transcription-service-agora-2-1024x184.png)

Screenshot of our site with the above code.

If you are not familiar with setting up a video call with Agora Web SDK, see [this tutorial](/en/blog/add-video-calling-in-your-web-app-using-the-agora-web-ng-sdk/) .

## Adding Color

Now that our basic layout is ready, it’s time to add some **CSS**. I’ve already added basic Bootstrap classes to the HTML to make the site presentable, but we’ll use custom CSS to match the site with a *blue* Agora-based theme:

transcription.css

```
.banner {
  padding: 10px;
  background-color: #1A0374;
  color: white;
}


.banner-text {
  padding: 8px 20px;
  margin: 0;
  font-size: 18px;
}




#join-form {
  margin-top: 10px;
}


.join-info-text {
  margin-bottom: 2px;
}


input {
  width: 100%;
  margin-bottom: 2px;
}


.player {
  width: 480px;
  height: 320px;
}


.player-name {
  margin: 8px 0;
}


#success-alert,
#success-alert-with-token {
  display: none;
}


@media (max-width: 640px) {
  .player {
    width: 320px;
    height: 240px;
  }
}


#join,
#leave,
#transcribe,
#stop-transcribe,
#note,
#stop-note {
  background-color: #0C9DFD;
  color: white;
  border-radius: 5px;
}


#join:hover,
#leave:hover,
#transcribe:hover,
#stop-transcribe:hover,
#note:hover,
#stop-note:hover {
  background-color: rgba(2, 133, 221, 0.911);
}


.transcribed-text {
  background: rgba(12, 157, 253, 0.897);
  padding: 30px;
  color: white;
  border-radius: 15px;
}
```

![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #3](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb03cf_building-your-own-transcription-service-agora-3-1024x282.png)

The magic of CSS.

![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #4](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb03de_building-your-own-transcription-service-agora-4.png)

**Understanding the UI controls:** First two buttons are to join/ leave a call. The next two buttons are to send transcription messages to all users in the channel. The last two buttons are to make personal transcriptions which others can’t see.

## Core Functionality (JS)

Now that we have the HTML/DOM structure laid out, we can add the JS, which uses the Agora Web SDK. It may look intimidating at first, but if you follow Agora’s [official docs](https://agoraio-community.github.io/AgoraWebSDK-NG/api/en/index.html) and [demos](https://agoraio-community.github.io/AgoraWebSDK-NG/demo/) and put in a little practice, it’ll be a piece of cake.

We first **create a client **(line 2)and specify the audio and the video tracks. When a user **joins **(line 43)a channel by clicking the button, the user’s stream is **subscribed** (line 91) and **published **(line 112).

Finally, we give the user an option to end the stream and **leave** (line 79) the channel:

transcription.js

```
// Create Agora RTC client
var client = AgoraRTC.createClient({ mode: "rtc", codec: "vp8" });
// Local Tracks
var localTracks = {
  videoTrack: null,
  audioTrack: null
};
var remoteUsers = {};
// Agora client options
var options = {
  appid: null,
  channel: null,
  uid: null,
  token: null,
  accountName: null
};


// Join Channel
$("#join-form").submit(async function (e) {
  e.preventDefault();
  $("#join").attr("disabled", true);
  try {
    options.appid = $("#appid").val();
    options.token = $("#token").val();
    options.channel = $("#channel").val();
    options.accountName = $('#accountName').val();
    await join();
  } catch (error) {
    console.error(error);
  } finally {
    $("#leave").attr("disabled", false);
    $("#transcribe").attr("disabled", false);
    $("#note").attr("disabled", false);
  }
})


// Leave Channel
$("#leave").click(function (e) {
  leave();
})


// Join Function
async function join() {
  // Add event listener to play remote tracks when remote user publishes
  client.on("user-published", handleUserPublished);
  client.on("user-unpublished", handleUserUnpublished);
  // Join a channel and create local tracks, we can use Promise.all to run them concurrently
  [options.uid, localTracks.audioTrack, localTracks.videoTrack] = await Promise.all([
    // Join the channel
    client.join(options.appid, options.channel, options.token || null),
    // Create local tracks, using microphone and camera
    AgoraRTC.createMicrophoneAudioTrack(),
    AgoraRTC.createCameraVideoTrack()
  ]);
  // Play local video track
  localTracks.videoTrack.play("local-player");
  $("#local-player-name").text(`localVideo(${options.uid})`);
  // Publish local tracks to channel
  await client.publish(Object.values(localTracks));
  console.log("Publish success");
}


// Leave Function
async function leave() {
  for (trackName in localTracks) {
    var track = localTracks[trackName];
    if (track) {
      track.stop();
      track.close();
      localTracks[trackName] = undefined;
    }
  }


  // Remove remote users and player views
  remoteUsers = {};
  $("#remote-playerlist").html("");


  // Leave the channel
  await client.leave();
  $("#local-player-name").text("");
  $("#join").attr("disabled", false);
  $("#leave").attr("disabled", true);
  $("#note").attr("disabled", true);
  $("#transcribe").attr("disabled", true);
  $("#stop-transcribe").attr("disabled", true);
  $("#stop-note").attr("disabled", true);
  console.log("Client leaves channel success");
}


// Subscribe function
async function subscribe(user, mediaType) {
  const uid = user.uid;
  // Subscribe to a remote user
  await client.subscribe(user, mediaType);
  console.log("Subscribe success");
  if (mediaType === 'video') {
    const player = $(`
      <div id="player-wrapper-${uid}">
        <p class="player-name">remoteUser(${uid})</p>
        <div id="player-${uid}" class="player"></div>
      </div>
    `);
    $("#remote-playerlist").append(player);
    user.videoTrack.play(`player-${uid}`);
  }
  if (mediaType === 'audio') {
    user.audioTrack.play();
  }
}


// User published callback
function handleUserPublished(user, mediaType) {
  const id = user.uid;
  remoteUsers[id] = user;
  subscribe(user, mediaType);
}


// User unpublish callback
function handleUserUnpublished(user) {
  const id = user.uid;
  delete remoteUsers[id];
  $(`#player-wrapper-${id}`).remove();
}
```

## Adding Voice-to-Text Services

Now that we have the core video calling functionality implemented, we can add the JS for transcription and note-making, which uses the Web Speech API to recognise speech, as well as the JS to send the transcribed text to all users in the channel using RTM. If you follow [this article](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API) to explore the functions in the Web Speech API and Agora’s [official docs](https://docs.agora.io/en/Real-time-Messaging/API%20Reference/RTM_web/v1.0.0/index.html) for RTM, you’ll be able to follow along without any difficulty.

We **initialise** the **Web Speech API** (lines 2 and 3) and set default global variable values. On button clicks for note-making (line 11), the transcribed text is automatically shown (line 31) to the user.

To send the same **transcribed text** to all other users in the channel, we use **RTM** to send messages consisting of the transcribed content.

We first **log in** (line 53)to the RTM client once it is initialised and **send messages** (line 82) to all connected users in the channel with new transcribed content.

We use the ***ChannelMessage*** callback (line 97) to receive and display the received message content:

transcription.js

```
// JavaScript Speech Recognition Init
var SpeechRecognition = window.webkitSpeechRecognition || window.speechRecognition;
var recognition = new webkitSpeechRecognition() || new SpeechRecognition();
var transContent = "";
var noteContent = "";
recognition.continuous = true;
// RTM Global Vars
var isLoggedIn = false;


// Start self notes
$("#note").click(function () {
  console.log('Voice recognition is on.');
  $("#stop-note").attr("disabled", false);
  $("#note").attr("disabled", true);
  $("#stop-transcribe").attr("disabled", true);
  $("#transcribe").attr("disabled", true);
  if (noteContent.length) {
    noteContent += ' ';
  }
  recognition.start();
});


// Stop self notes
$("#stop-note").click(function () {
  console.log('Voice recognition is off.');
  recognition.stop();
  recognition.onresult = function (event) {
    var current = event.resultIndex;
    var transcript = event.results[current][0].transcript;
    noteContent = noteContent + transcript + "<br>";
    $("#note-text").append("<b><i>You said: </i></b> " + noteContent);
    noteContent = '';
  };
  $("#note").attr("disabled", false);
  $("#stop-note").attr("disabled", true);
  $("#stop-transcribe").attr("disabled", true);
  $("#transcribe").attr("disabled", false);
});


// Can't recognise voice
recognition.onerror = function (event) {
  if (event.error == 'no-speech') {
    console.log('Could you please repeat? I didn\'t get what you\'re saying.');
    recognition.stop();
    recognition.start();
  }
}


// Create Agora RTM client
const clientRTM = AgoraRTM.createInstance($("#appid").val(), { enableLogUpload: false });
var accountName = $('#accountName').val();
// Login
clientRTM.login({ uid: accountName }).then(() => {
  console.log('AgoraRTM client login success. Username: ' + accountName);
  isLoggedIn = true;
  // RTM Channel Join
  var channelName = $('#channel').val();
  channel = clientRTM.createChannel(channelName);
  channel.join().then(() => {
    console.log('AgoraRTM client channel join success.');
    // Start transcription for all (RTM)
    $("#transcribe").click(function () {
      console.log('Voice recognition is on.');
      $("#transcribe").attr("disabled", true);
      $("#stop-transcribe").attr("disabled", false);
      $("#stop-note").attr("disabled", true);
      $("#note").attr("disabled", true);
      if (transContent.length) {
        transContent += ' ';
      }
      recognition.start();
    });
    // Stop transcription for all (RTM)
    $("#stop-transcribe").click(function () {
      console.log('Voice recognition is off.');
      recognition.stop();
      recognition.onresult = function (event) {
        var current = event.resultIndex;
        var transcript = event.results[current][0].transcript;
        transContent = transContent + transcript + "<br>";
        singleMessage = transContent;
        channel.sendMessage({ text: singleMessage }).then(() => {
          console.log("Message sent successfully.");
          console.log("Your message was: " + singleMessage + " by " + accountName);
          $("#actual-text").append("<br> <b>Speaker:</b> " + accountName + "<br> <b>Message:</b> " + singleMessage + "<br>");
          transContent = ''
        }).catch(error => {
          console.log("Message wasn't sent due to an error: ", error);
        });
      };
      $("#note").attr("disabled", false);
      $("#stop-note").attr("disabled", true);
      $("#stop-transcribe").attr("disabled", true);
      $("#transcribe").attr("disabled", false);
    });
    // Receive RTM Channel Message
    channel.on('ChannelMessage', ({ text }, senderId) => {
      console.log("Message received successfully.");
      console.log("The message is: " + text + " by " + senderId);
      $("#actual-text").append("<br> <b>Speaker:</b> " + senderId + "<br> <b>Message:</b> " + text + "<br>");
    });
  }).catch(error => {
    console.log('AgoraRTM client channel join failed: ', error);
  }).catch(err => {
    console.log('AgoraRTM client login failure: ', err);
  });
});


document.getElementById("leave").onclick = async function () {
    console.log("Client logged out of RTM.");
    await clientRTM.logout();
}
```

*You can now run and test the application.*

![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #5](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb0405_building-your-own-transcription-service-agora-5-1024x571.png)

Screenshot of the demo from user 1’s perspective.

![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #6](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb03e7_building-your-own-transcription-service-agora-6-1024x571.png)

Screenshot of the demo from user 2's perspective.

***Note:**** For testing, you can use two or more browser tabs to simulate multiple users on the call.*

## Conclusion

### You did it!

We have successfully made our very own transcription and note-making service inside a web video call application. In case you weren’t coding along or want to see the finished product all together, I have uploaded all the code to GitHub:

[![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #7](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb040d_building-your-own-transcription-service-agora-7-1024x260.png)](https://github.com/akshatvg/Agora-Transcription)

You can check out the demo of the code in action:

[![Building Your Own Transcription Service Within a Video Call Web App - Screenshot #8](/_assets/assets/agoras-website-assets/images/6669da1f665f17bec4eb03c6_building-your-own-transcription-service-agora-8png-1024x136.png)](https://transcription.akshatvg.com/)

Thanks for taking the time to read my tutorial. If you have questions, please let me know with a comment. If you see room for improvement, feel free to fork the repo and make a pull request!

## Related products

- [Product Video Calling & Streaming Explore product](/en/products/video-calling-streaming/)

- [Product Agora Signaling Explore product](/en/products/signaling/)

Share

## Keep reading

[![Build a Live Translated Transcriptions Service in Your Video Call Web App](/_assets/assets/agoras-website-assets/images/667330c66233a6e0023115a1_build-a-live-translated-transcriptions-service-within-your-video-call-web.png) Developer December 22, 2021 Build a Live Translated Transcriptions Service in Your Video Call Web App Learn how to make a real-time translation service using the Agora Web SDK and Google Cloud. Read article](/en/blog/build-a-live-translated-transcriptions-service-in-your-video-call-web-app/)

[![Muting And Unmuting A Remote User In A Video Call Web](/_assets/assets/agoras-website-assets/images/66733081d4600e84352018fd_muting-and-unmuting-a-remote-user-in-a-video-call-web-app-agora.png) Developer July 26, 2021 Muting And Unmuting A Remote User In A Video Call Web Learn how to build a group video call web application with a service to mute or unmute remote users using the Agora Web and RTM SDKs. Read article](/en/blog/muting-and-unmuting-a-remote-user-in-a-video-call-web/)

[![Highlighting The Active Speakers During A Group Video Call](/_assets/assets/agoras-website-assets/images/6673307e4a65ebb2b121dc73_highlighting-the-active-speakers-in-a-group-video-call-agora.png) Developer July 23, 2021 Highlighting The Active Speakers During A Group Video Call A step-by-step tutorial on how to build a group video calling application which highlights the active speaker using the Agora Web SDK. Read article](/en/blog/highlighting-the-active-speakers-during-a-group-video-call/)
