This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Add live captions to a video call app with daily-js


At Each day, we love seeing what builders construct in no matter method works finest for them. We provide Daily Prebuilt – our embeddable video name UI – to get began with only a couple traces of code or you may construct a completely customized experiences with Each day’s call object. Our aim is to help everybody’s use case and talent stage by making browser-based video calls simple to combine and customise.

As a part of making the decision expertise higher for everybody, we now have launched the flexibility so as to add dwell captions to Each day domains with our startTranscription() occasion technique in partnership with Deepgram.

This extremely requested function has many makes use of. They embody having the ability to:

  • Introduce wider accessibility choices inside calls
  • Present an “prompt replay” (e.g. What did they only say?)
  • Produce an effective way to generate assembly notes

video call participant's audio being transcribed in the demo app

This tutorial focuses on pairing transcription with Each day Prebuilt. We have already got an intensive tutorial on adding transcription to a custom Daily call, which you must positively take a look at! Immediately’s tutorial features a demo that walks by means of the way to add transcription alongside a Each day Prebuilt name.

In case you are like spoilers and need to see what we’re constructing in the present day, you may bounce straight into the prebuilt-transcription code and in addition strive a live demo

Observe: You’ll have to join your Each day and Deepgram accounts, as outlined within the demo’s README and on this tutorial, to completely expertise the dwell demo.

What’s the plan?

On this tutorial, we are going to cowl:

  • Getting arrange with Each day and Deepgram
  • Embedding Each day Prebuilt in a Subsequent.js app
  • Making a transcription part
  • Including buttons to begin and cease transcription strategies
  • Loading the dwell captions
  • Optimizing the app for giant quantities of textual content
  • Downloading the transcript
    ## Conditions

As a result of transcription is a shared service between Each day and Deepgram, there’s a little bit of set-up concerned to get each companies operating with one another. However the excellent news is you could set it and neglect it, as a result of it’s only a one-time step!

Observe: Each day doesn’t cost for transcription companies and Deepgram provides a free $150 credit score upon sign-up, so there isn’t any price related to this tutorial.

To stroll by means of this tutorial, you’ll first have to create a Daily account and a Deepgram account. After getting an account and are logged into the Daily Dashboard, you may create a new Daily room or use our REST API.

To arrange transcription, you’ll have to enable_transcription on your Daily domain.

Basically, you will want your Each day API key, obtainable within the Daily dashboard, and your Deepgram API key to replace your area settings, like so:

curl --request POST 
    --url https://api.every 
    --header 'Settle for: software/json' 
    --header 'Authorization: Bearer YOUR_DAILY_API_KEY' 
    --header 'Content material-Sort: software/json' 
    --data '{"properties": { "enable_transcription": "deepgram:YOUR_DEEPGRAM_API_KEY" }}'
Enter fullscreen mode

Exit fullscreen mode

Establishing the demo

Head on over to the prebuilt-transcription GitHub repository and fork the repo to observe together with the remainder of this put up.

After forking and navigating to the prebuilt-transcription folder, set up the dependencies:

npm i
Enter fullscreen mode

Exit fullscreen mode

And run the dev server:

npm run dev
Enter fullscreen mode

Exit fullscreen mode

Regionally, open http://localhost:3000 in your browser.

This demo relies on the Next.js React framework, beginning with the create-next-app template builder. This tutorial additionally makes use of TypeScript. In case you are new to TypeScript, no worries! As a result of it’s constructed on high of JavaScript, it appears very related with a number of extra options and syntax.

Staging the [room]

Probably the most attention-grabbing a part of our codebase lives in pages/[domain]/[room].tsx, so let’s begin there. And sure, these brackets are a part of the file names – this permits us to create URLs dynamically in Subsequent.js.

After we load the web page, we need to construct and begin the decision straight away with the parameters we retrieve from the web page URL. To do that, we create a useCallback operate:

   Arrange the Each day name and occasion listeners on web page load

 const startCall = useCallback(() => {
   const iframe = doc.getElementById("callFrame");
   const newCallFrame = DailyIframe.wrap(iframe as HTMLIFrameElement, {
     showLeaveButton: true,
   setCallFrame(newCallFrame); part of({
     url: url,

   newCallFrame.on("joined-meeting", (ev) => {
     let ownerCheck = ev?.individuals.native.proprietor as boolean;

  // snip snip - some extra occasion listeners right here 
  // we’ll come again to this part later!

 }, [url]);
Enter fullscreen mode

Exit fullscreen mode

The above startCall operate hundreds when the web page hundreds, by way of a React useEffect:

 useEffect(() => {
 }, [startCall]);
Enter fullscreen mode

Exit fullscreen mode

This creates and joins a name constructed from the URL parameters.

Incorporating the Each day Prebuilt iframe

Now that the app framework is up and operating, let’s add Each day Prebuilt. Since Each day Prebuilt is an embeddable video name UI, Each day has already carried out many of the video-related be just right for you. Which means this half can be quick.

From the aforementioned [room].tsx web page, we load the <CallFrame> part. The complete part appears like this:

import types from "../types/CallFrame.module.css";

const CallFrame = () => (
 <div className={types.callFrameContainer}>
     enable="microphone; digital camera; autoplay; display-capture"

export default CallFrame;
Enter fullscreen mode

Exit fullscreen mode

The few traces of styling imported from ../types/CallFrame.module.css enable the Each day Prebuilt iframe to take up many of the display:

.callFrameContainer {
 width: 100%;
 peak: 80%;

.callFrame {
 width: 100%;
 peak: 100%;
 min-height: 80vh;
 border: 0;
Enter fullscreen mode

Exit fullscreen mode

With out this styling for the <iframe> and its container, Each day Prebuilt defaults to taking on solely a small quantity of house on the web page. You may change the styling nonetheless you want and Each day Prebuilt will match inside these constraints.

Observe: We’re utilizing wrap() so as to add Each day Prebuilt to an present <iframe>, however you may additionally use the createFrame technique to make a brand new <iframe>, model that body, and add it to the web page.

Video call UI when a token or call owner is not present and transcription can't be used

Transcription part

Now that we now have Each day Prebuilt loaded on the web page, let’s begin implementing transcription by including a part to retailer our buttons and transcript.

From our [room].tsx, we reference the Transcription part and go some managed state to the part:

  • callFrame: passes the Each day name body object, which permits the part to begin and cease transcription
  • newMsg: sends every new transcripted message to the part for exhibiting the textual content within the transcript window
  • proprietor: this boolean tells the part whether or not the present person is or isn’t a room owner
  • isTranscribing: this boolean tells the part that Each day is or isn’t presently transcribing.
Enter fullscreen mode

Exit fullscreen mode

In our Transcription part (outlined in elements/Transcription.tsx), we now have a button that toggles the choice to begin or cease transcription based mostly on whether or not transcription is presently energetic in line with Each day (we’ll come again to that in a second):

 onClick={() => {
   isTranscribing ? stopTranscription() : startTranscription();
 {isTranscribing ? "Cease transcribing" : "Begin transcribing"}
Enter fullscreen mode

Exit fullscreen mode

If the assembly participant isn’t an proprietor, this button can be disabled together with a message explaining that solely assembly room homeowners can begin transcription.

This button makes use of these two easy capabilities:

 async operate startTranscription() {

 async operate stopTranscription() {
Enter fullscreen mode

Exit fullscreen mode

How do these capabilities know if transcription is occurring or not? For that, we bounce again to [room].tsx. Earlier within the put up, we appeared on the primary construction of the startCall operate. In our demo, this operate additionally has a number of traces devoted to Each day occasion listeners. We’re listening to some Each day-emitted occasions that assist us form the video name expertise. Two of those occasions are transcription-started and transcription-stopped occasions.

When these occasions are emitted, we all know to replace the React state to set isTranscribing to its right boolean worth.

   newCallFrame.on("transcription-started", () => {

   newCallFrame.on("transcription-stopped", () => {
Enter fullscreen mode

Exit fullscreen mode

Observe: You may also use our new Daily React Hooks library to extra shortly join your React-based app with Each day’s JavaScript API!

Including transcription

Now that we’re capable of begin and cease transcription, we have to add the transcripts to the web page. Our transcripts are available from Each day by way of an ”app-message” occasion. For that, we want one other occasion listener inside our startCall operate. This checks whether or not every ”app-message” got here from the ID of “transcription” and whether or not it’s a full sentence (that’s what information.is_final is doing under). When we now have a message, we save the message as an object with the writer’s username, the textual content transcription, and a timestamp.

     (msg: DailyEventObjectAppMessage | undefined) => {
       const information = msg?.information;
       if (msg?.fromId === "transcription" && information?.is_final) {
         const native = newCallFrame.individuals().native;
         const identify: string =
           native.session_id === information.session_id
             ? native.user_name
             : newCallFrame.individuals()[data.session_id].user_name;
         const textual content: string = information.textual content;
         const timestamp: string = information.timestamp;

         if (identify.size && textual content.size && timestamp.size) {
           setNewMsg({ identify, textual content, timestamp });
Enter fullscreen mode

Exit fullscreen mode

We’d like some React state to carry messages, so we arrange a const the place we instantiate this state as an empty array to carry incoming message objects.

const [messages, setMessage] = useState<Array<transcriptMsg>>([]);
Enter fullscreen mode

Exit fullscreen mode

That is primarily all that must be carried out to get transcription on the web page. You may loop by means of this array of messages and add them to the display, or you may add every new message to the display because it arrives. Nonetheless, there’s one further step value taking to optimize your app for all of those messages, and we’ll see how that works within the subsequent part.

Observe: Transcript messages are ephemeral. They’re solely obtainable for the message the person has obtained whereas they’re within the room. For those who refresh your web page, you’ll lose the transcripts. Equally, new customers will solely see a transcript for conversations which have taken place since they’ve joined and never a historical past.

Transcribed text scrolling up and down

Optimize your window

Seeing transcripts seem on the display is tremendous enjoyable, however it will possibly shortly decelerate browser home windows with the addition of so many DOM parts getting added to the display. Beneath, we’ll cowl not simply how we add transcript messages to our web page, but additionally the way to do it in a method that’s environment friendly and never overwhelming to anybody’s browser.

To assist with this, we have to add two dependencies to our app: react-window and react-virtualized-auto-sizer. These libraries assist us by loading solely the latest messages. As an alternative of loading the complete array of message objects as HTML, the DOM solely hundreds the small a part of the information set seen within the window. This virtualization approach prevents poor efficiency brought on by an overloaded browser tab holding an excessive amount of information in reminiscence. Customers can nonetheless scroll up and see earlier messages that are loaded as wanted when requested.

We’ve got established consts for the transcript record and rows that instantiate as empty objects.

 const listRef = useRef<any>({});
 const rowRef = useRef<any>({});
Enter fullscreen mode

Exit fullscreen mode

We add new messages obtained from the mother or father [room] web page to an array. We even have a small operate that retains the array of messages transferring to the underside (most up-to-date) ingredient each time a message is obtained.

 useEffect(() => {
   setMessage((messages: Array<transcriptMsg>) => {
     return [...messages, newMsg];
 }, [newMsg]);

 useEffect(() => {
   if (messages && messages.size > 0) {
     return () => {
 }, [messages]);
Enter fullscreen mode

Exit fullscreen mode

For every row, we name a formatting operate. It constructions the transcript within the model of “Message Writer: Message Textual content” on the left and Timestamp trimmed to an area time solely on the suitable (styled with CSS, the handy-dandy float:proper).

 operate Row({ index, model }: rowProps) {
   const rowRef = useRef<any>({});

   useEffect(() => {
     if (rowRef.present) {
       setRowHeight(index, rowRef.present.clientHeight);
   }, [rowRef]);

   return (
     <div model={model}>
       {messages[index].identify && (
         <div ref={rowRef}>
           {messages[index].identify}: {messages[index].textual content}
           <span className={types.timestamp}>
             {new Date(messages[index].timestamp).toLocaleTimeString()}
Enter fullscreen mode

Exit fullscreen mode

Our rendered transcript block then appears like this, with every loaded row wrapped within the react-window Checklist and react-virtualized-auto-sizer AutoSizer parts.

 {({ peak, width }) => (
Enter fullscreen mode

Exit fullscreen mode


The transcripts collected on this app aren’t obtainable after the decision concludes, so downloading them is useful if you wish to use them later.

To do this, we want to organize a chat file with all the textual content, not simply the textual content presently virtualized on the display.

We’ve got already seen that we’re utilizing React state to gather and set messages. For getting ready a plain textual content file with the transcript inside, we are going to add a transcriptFile state that instantiates as an empty string.

const [transcriptFile, setTranscriptFile] = useState<string>("");
Enter fullscreen mode

Exit fullscreen mode

Subsequent, let’s arrange a useEffect to model the transcript in a method that works finest for reviewing later. Not like the dwell transcript the place we now have the timestamp on the suitable and set to native time solely, this contains the total timestamp and date for each message.

   Enable person to obtain most up-to-date full transcript textual content

 useEffect(() => {
       new Blob( =>
             ? `${msg.timestamp} ${msg.identify}: ${msg.textual content}n`
             : `Transcriptn`
         { sort: "octet/stream" }
 }, [messages]);
Enter fullscreen mode

Exit fullscreen mode

This hyperlink will get the latest full transcript and by default reserve it as a file referred to as transcript.txt, though this may be modified later by the person.

<a href={transcriptFile} obtain="transcript.txt">
  Obtain Transcript
Enter fullscreen mode

Exit fullscreen mode


And there you’ve it! Utilizing Each day Prebuilt and our new Transcription API with Deepgram, it’s not an excessive amount of work so as to add a dwell transcript to your conferences. From what we’ve proven on this demo, you may simply add totally different types (together with to the Each day Prebuilt window itself by customizing with your own color themes)

We might like to see what you’ve constructed utilizing Each day. Attain out to us anytime at!

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?