Analyze Audio from Zoom Calls with AssemblyAI and Node.js

Analyze Audio from Zoom Calls with AssemblyAI and Node.js

Analyze Audio from Zoom Calls with AssemblyAI and Node.js

Including AI in digital conferences can considerably improve effectivity and the person expertise. For instance, AI speech providers can present and analyze transcriptions to supply numerous insights from the assembly, akin to an actionable merchandise listing or an in depth abstract.

In this tutorial, you may discover ways to get and parse audio from a Zoom name, transcribe the audio utilizing AssemblyAI, after which course of and analyze the transcribed audio utilizing AssemblyAI’s LeMUR API and audio intelligence fashions.

Set up your growth atmosphere

To comply with this tutorial, you first have to arrange your growth atmosphere, set up the required dependencies, and retrieve and securely retailer your AssemblyAI API key.

First, create a brand new venture listing and cd into it by working the command under in your terminal:

mkdir assemblyai-zoom && cd assemblyai-zoom

Then, run the command under to initialize npm in your venture:

npm init -y

Run the next command to put in the dependencies required in your venture:

npm set up assemblyai dotenv fluent-ffmpeg node-media-server

Here’s brief description of every of the packages you simply put in:

  • assemblyai: The AssemblyAI’s Node.js SDK, which is able to make it simpler so that you can work together with AssemblyAI.
  • dotenv: Dotenv is a Node.js package deal that masses environmental variables into course of.env. You’ll want this package deal to handle your environmental variables.
  • fluent-ffmpeg: This is a Node.js library that abstracts the complicated command line utilization of FFmpeg right into a simple-to-use package deal. You’ll want this package deal to course of your audio earlier than sending it to AssemblyAI.
  • node-media-server: Node Media Server is a Node.js implementation of a number of media servers, together with RTMP. You’ll want this package deal to create your customized streaming server the place you obtain an RTMP stream.

Next, create a .env file in your venture’s root listing and add the variable under to it:

ASSEMBLYAI_API_KEY =

In the subsequent part, you may get your AssemblyAI API key and add it to this .env file.

Get your API key

To get your AssemblyAI API key, you want to have an AssemblyAI account; you may join free if you do not have one.

If you have already got an AssemblyAI account, go forward and log in. On your welcome dashboard, you must see your API key on the fitting aspect of your display:

Analyze Audio from Zoom Calls with AssemblyAI and Node.js

Click the Copy API key button and paste the API key in your .env file as the worth of ASSEMBLYAI_API_KEY.

Get audio from a Zoom name

There are a number of methods you may get audio from a Zoom name. Still, essentially the most possible choices are streaming the decision to a customized media server utilizing Real-Time Messaging Protocol (RTMP) and Zoom recordings (cloud and native). An different possibility could be to construct a bot or use a third-party service that may be a part of conferences and file the audio, however these choices would incur additional prices within the type of engineering effort or a subscription to a premium service.

For this tutorial, you may stream the audio utilizing RTMP and save the audio domestically as an MP3 file. However, relying in your use case in actual life, you may need to retailer the audio on the cloud.

To stream audio from a Zoom name to a customized media server utilizing RTMP, you will need to have a Pro plan or greater on Zoom. Additionally, you want to allow livestreaming for conferences in your account.

Next, you may want a customized media server to obtain the audio stream out of your Zoom name.

Create a customized media server

To create a customized media server, begin by making a brand new src folder in your venture’s root listing. Then, create a mediaServer.js file in your src folder with the code under:

// mediaServer.js
const NodeMediaServer = require("node-media-server");
const course ofAudioStream = require("./audioProcessor");

const config = {
  rtmp: {
    port: 1935,
    chunk_size: 60000,
    gop_cache: true,
    ping: 30,
    ping_timeout: 60,
  },
  http: {
    port: 8000,
    allow_origin: "*",
  },
};

const nms = new NodeMediaServer(config);

// Listen for the "prePublish" occasion to start out processing the audio stream
nms.on("prePublish", (id, StreamPath, args) => {
  console.log(`Stream [${id}] is about to be printed at path: ${StreamPath}`);
  course ofAudioStream(StreamPath);
});

nms.run();

This code units up a Node.js server for a customized streaming service. It begins by importing the NodeMediaServer library and a course ofAudioStream operate (you may implement this later). Then, it creates a configuration object in your media server.

The config object comprises the configuration in your rtmp and http servers.

The configuration for RTMP contains the next:

  • port: This possibility represents the port on which the RTMP server listens for visitors. 1935 is the default port.
  • chunk_size: This possibility specifies the dimensions of the information chunks that the server sends over the community, and it is measured in bytes. In this configuration, the chunk dimension is ready to 60,000 bytes.
  • gop_cache: Setting gop_cache to true permits the server to cache every stream’s newest group of images (GOP).
  • ping: This possibility specifies the interval, in seconds, at which the server sends RTMP ping messages to linked purchasers to maintain the connection alive and measure the round-trip time. In this configuration, the server will ship a ping each thirty seconds.
  • ping_timeout: This is the timeout (in seconds) for RTMP ping responses. The server closes the connection if the shopper does not reply to a ping message inside this time. In this configuration, the timeout is ready to sixty seconds.

The configuration for the HTTP server contains the next:

  • port: This is the port quantity on which the HTTP server will hear for visitors. In this configuration, the port is ready to 8000.
  • allow_origin: This setting specifies which origins could make cross-origin requests to the server. The wildcard * is used on this configuration, that means the server will settle for cross-origin requests from any origin.

After organising the configuration object, it creates an occasion of NodeMediaServer and listens for the prePublish occasion. On the prePublish occasion, it calls the course ofAudioStream operate and passes StreamPath as an argument.

You’ve now arrange your customized streaming service. In the subsequent step, you may use FFmpeg to parse the audio from the RTMP stream.

Parse audio from an RTMP stream

RTMP streams sometimes comprise each audio and video information multiplexed collectively. To use the audio information individually, you want to extract it from the mixed stream and retailer it. For this tutorial, you may retailer the extracted audio in an MP3 file.

To be certain that every audio file has a singular identify, you may create a utility operate that mixes the present date (YYYY-MM-DD) and the timestamp to generate distinctive file names.

Create a utils.js file in your src folder and add the next code to it to implement the logic above:

operate getFormattedDateTime() {
  const now = new Date();
  const 12 months = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, "0");
  const day = String(now.getDate()).padStart(2, "0");
  const timestamp = Date.now();
  return `${12 months}${month}${day}_${timestamp}`;
}

module.exports = { getFormattedDateTime };

Next, create an audioProcessor.js file in your src folder and add the code block under to implement the logic for parsing the audio and saving the parsed audio to an MP3 file:

const ffmpeg = require("fluent-ffmpeg");
const { getFormattedDateTime } = require("./utils");

operate course ofAudioStream(streamPath) {
  const inputPath = `rtmp://localhost:1935${streamPath}`;
  const outputPath = `./src/recordings/meeting_${getFormattedDateTime()}.mp3`;

  ffmpeg(inputPath)
    .outputOptions("-q:a 0") // Set the audio high quality to the best high quality
    .outputOptions("-map a") // Map solely the audio streams
    .on("begin", (commandLine) => {
      console.log("Spawned FFmpeg with command: " + commandLine);
    })
    .on("progress", (progress) => {
      console.log("Processing: " + progress.timemark + "...");
    })
    .on("error", (err, stdout, stderr) => {
      console.log("An error occurred: " + err.message);
      console.log("FFmpeg stderr: " + stderr);
    })
    .on("finish", () => {
      console.log("Processing completed!");
    })
    .save(outputPath);
}

module.exports = course ofAudioStream;

The code above listens to an RTMP stream, extracts the audio, and saves it as an MP3 file with prime quality. It additionally gives detailed logs for the FFmpeg begin, progress, error, and finish occasions.

Finally, begin your server by working the command under:

node src/mediaServer

With this setup, as soon as your media server receives an RTMP stream and emits the prePublish occasion, it is going to parse the audio from the stream and put it aside to an MP3 file.

Make your customized media server accessible with ngrok

Currently, your media server is hosted on localhost. You have to make it accessible to Zoom utilizing ngrok.

To proceed, you want to set up ngrok and set it up in your working system. Then, run the command under to get the situation of your ngrok configuration file:

ngrok config examine

cd into the listing returned by the command above, open your ngrok.yml file, and add the configuration under to run your TCP and HTTP ports:

tunnels:
  tcp_tunnel:
    proto: tcp
    addr: 1935
  http_tunnel:
    proto: http
    addr: 8000

You can now run ngrok with the command under:

ngrok begin --all

You ought to see an output just like the next in your terminal:

Analyze Audio from Zoom Calls with AssemblyAI and Node.js

Save your forwarding URLs. In the picture above, these are tcp://5.tcp.eu.ngrok.io:13156 (this might be your streaming URL) and https://c9f0-105-114-3-2.ngrok-free.app (this might be your livestreaming web page URL).

Stream audio to your customized reside streaming service

In an ongoing Zoom name, click on the three dots on the underside proper of your display and choose Live on Custom Live Streaming Service:

Analyze Audio from Zoom Calls with AssemblyAI and Node.js

You’ll be introduced with a kind to fill in your livestreaming server’s info.

The fields within the kind embrace:

  • Streaming URL: The base URL the place your stream needs to be transmitted, which is the forwarding URL in your RTMP server you saved earlier. Change the protocol within the URL from tcp to rtmp. Then, append /reside to the top of the URL to specify the route the place the stream is directed—for instance, rtmp://5.tcp.eu.ngrok.io:13156/reside.
  • Streaming key: A singular identifier the streaming server makes use of to acknowledge and handle incoming streams. It acts as a password or token that authorizes the stream being despatched to the server. You can fill the streaming key with any worth of your alternative, akin to ZOOM.
  • Live streaming web page URL: The URL the place you may view your stream. In this case, it is your HTTP forwarding URL with the route /admin/streams appended to it—for instance, https://c9f0-105-114-3-2.ngrok-free.app/admin/streams.

Fill out the fields with their applicable values and click on the Go Live! button:

Analyze Audio from Zoom Calls with AssemblyAI and Node.js

This redirects you to your customized streaming server:

https://i.imgur.com/fNjo6ok.jpeg

Your customized streaming service is now recording your Zoom name audio and can put it aside to an MP3 file as soon as your name ends otherwise you finish the livestream.

Transcribe audio with AssemblyAI

Now that you’ve your Zoom audio, you may get the transcript utilizing AssemblyAI. To obtain this, you want to initialize the AssemblyAI SDK utilizing your API key.

Create an assemblyai.js file and add the code block under to initialize your SDK:

require("dotenv").config();
const { AssemblyAI } = require("assemblyai");

// Create a brand new AssemblyAI shopper
const shopper = new AssemblyAI({
  apiKey: `${course of.env.ASSEMBLYAI_API_KEY}`,
});

module.exports = shopper;

To transcribe a neighborhood audio file utilizing AssemblyAI, name the transcribe technique on shopper.transcripts and go the file path as an argument.

Here’s a standalone instance:

const shopper = require("./assemblyai");

const transcribeAudio = async (filePath) => {
  const transcript = await shopper.transcripts.transcribe({ audio: filePath });

  console.log(transcript.textual content);

  return transcript;
};

transcribeAudio("src/recordings/FILE_PATH_TO_AUDIO");

In this code, the transcribeAudio operate takes a file path as an argument and returns a transcript. If your audio file is saved on the cloud, you may go the audio URL as an argument to transcribe it. Running the code will return a full transcript of the audio whose location you handed as an argument.

Analyze audio with AssemblyAI’s massive language and audio intelligence fashions

AssemblyAI gives an API known as LeMUR, which lets you apply massive language fashions (LLMs) to spoken information. LeMUR lets you carry out numerous duties in your audio information, akin to asking questions concerning the information, summarizing the audio information, producing content material primarily based on the audio information, and far more.

The following instance makes use of a recorded assembly concerning the "paradox of poverty." You can use LeMUR to summarize it, and you may as well add a context possibility to supply info not explicitly referenced within the audio information and specify a solution format:

const shopper = require("./assemblyai");

const summarizeAudioWithLeMUR = async (filePath) => {
  const transcript = await shopper.transcripts.transcribe({ audio: filePath });

  const { response } = await shopper.lemur.abstract({
    transcript_ids: [transcript.id],
    context: "A chat on the paradox of poverty",
    answer_format: "bullet factors",
  });

  console.log(response);

  return response;
};

summarizeAudioWithLeMUR("src/recordings/meeting_20240603_1717405934474.mp3");

The code block above will return the abstract of the audio file in bullet factors.

You may also ship any immediate of your option to the LLM and apply the mannequin to your transcribed audio utilizing the LeMUR activity endpoint.

You can ship prompts to ask particular questions on your audio information, like "How many occasions was the phrase ‘poverty’ used within the assembly?" or "List the examples of welfare traps."

For instance, the code block under demonstrates how you need to use a immediate ("What is the primary concept of the speak?") to question your audio information to get the primary concept of the audio:

const analyzeAudioWithLemurTask = async (filePath, immediate) => {
  const transcript = await shopper.transcripts.transcribe({ audio: filePath });

  const { response } = await shopper.lemur.activity({
    transcript_ids: [transcript.id],
    immediate,
  });

  console.log(response);

  return response;
};

analyzeAudioWithLemurTask(
  "src/recordings/meeting_20240603_1717405934474.mp3",
  "What is the primary concept of the speak?"
);

The code block above will return a response detailing the primary concept of the audio handed as an argument.

Audio intelligence fashions

AssemblyAI additionally gives numerous audio intelligence fashions that may carry out a number of duties akin to content material moderation, personally identifiable info (PII) redaction, and sentiment evaluation, amongst others.

Let’s take an instance of PII redaction in your audio transcript to attenuate delicate details about people by routinely figuring out and eradicating them. To allow PII redaction, you want to add just a few configuration parameters. The following code block is a modified model of the transcribeAudio operate with the required parameters:

const transcribeAudioWithPIIRedaction = async (filePath) => {
  const transcript = await shopper.transcripts.transcribe({
    audio: filePath,
    redact_pii: true,
    redact_pii_policies: [
      "banking_information",
      "phone_number",
      "email_address",
    ],
    redact_pii_sub: "hash",
  });

  console.log(transcript.textual content);

  return transcript;
};

transcribeAudioWithPIIRedaction(
  "src/recordings/meeting_20240603_1717405934474.mp3"
);

The parameters you added listed below are as follows:

  • redact_pii: This is a Boolean worth that, when set to true, permits PII redaction within the transcript.
  • redact_pii_policies: This is an array of knowledge to be redacted. In the instance above, you have got banking info, cellphone numbers, and e mail addresses.
  • redact_pii_sub: This refers to what the redacted info needs to be changed with. In the instance above, the redacted info might be changed with hashes (###).

The code block will return a transcript with all the required PII redacted.

You can discover the code used on this tutorial in this GitHub repository.

Conclusion

In this text, you discovered extract audio information from a Zoom name utilizing RTMP, Node Media Server, and FFmpeg. You additionally discovered transcribe the audio utilizing AssemblyAI’s transcription fashions, apply LLMs to it utilizing LeMUR, and manipulate the audio transcriptions utilizing audio intelligence fashions.

HI-FI News

through News, Tutorials, AI Research https://ift.tt/a96XEUx

August 28, 2024 at 05:02PM