Build a Python App Using Assembly AI's Speech-To-Text API
Learn how to develop a Python app with Assembly AI's API for call analysis, sentiment, and Lemur's action item retrieval, perfect for real-world applications.
File
Python Tutorial For Call Center Analysis With AI Using Speech-To-Text
Added on 01/29/2025
Speakers
add Add new speaker

Speaker 1: Hello, everyone. In this video, we're going to be building a very simple Python application, which makes use of machine learning to analyze customer calls. To do this, we're going to be making use of Assembly AI's powerful speech-to-text API, as well as their LLM framework, Lemur. To start off, let's take a look at what our end result will look like. Here is a customer call about a missing package. According to the FedEx tracking, your parcel was delivered on Monday and left at your front porch. That's impossible. My apartment doesn't even have a front porch. Also, I was home all day on Monday, and no one attempted to deliver a parcel. And side by side, you can see our application making use of Lemur to retrieve action items from the call. And this is an excellent real-world use case, which is used by a ton of different companies. To start off, we are going to be coding the logic of this application in Google Colab so it's much more easier to run and understand. And before we do that, to make use of Assembly AI's API, be sure to go ahead and create a free API key, which we'll be using in the application. And the link to the API will be in the description box below. Let's take a look at our application and analyze the core logic behind it. The first thing we're doing is selecting an audio for analysis. What this does is it allows us to upload an audio file to Assembly AI's speech-to-text API, which then transcripts that audio file for further analysis. And that is exactly what our first function here, sendToAPI, is going to do. The second thing that we're looking at is sentiment analysis. And that is what our second function over here, analyzeSentiment, is going to do. The third thing that we're going to be doing is generating action items by making use of the Lemur framework. And that is what the third method over here is going to be handling. So getActionItems is going to be generating action items from Assembly AI's Lemur framework. To start off, the first thing we're going to do is install Assembly AI's Python library into Google Colab. And we can do that easily by running pip install assemblyAI. Once we've done that, we're going to get started on our first function, sendToAPI. The first thing we're doing in the sendToAPI function is defining our API key. And this right here is where you should be writing your own API key, which you can get from your Assembly AI account. So this first function, sendToAPI, is complete. And what we have essentially written is we have created a transcriber object, which will help to transcribe our audio file. And once we've done that, we've created a transcript variable where we'll be storing our actual transcript that we get from Assembly AI's API. Once we have gotten that transcript, what we're going to do is we're going to pass it into our two other functions, which is analyzing sentiment and getActionItems. And these are going to be giving us sentiment values and retrieving action items by making use of the Lemur framework. Once we've done that, we're going to return a JSON object, which includes both the sentiment that we get and also the action items. And essentially, this JSON object is going to make it really easy for us to pass this data into our application UI later on. So this is the AnalyzeSentiment function, and this is how it works. So Assembly AI Speech-to-Text API returns a sentiment value for every single sentence which was spoken in the audio file that we sent it. And what this function does is it counts all the positive instances and negative instances. So whichever is higher, that's the sentiment that we're assigning to the entire call. And this is the basic logic of this function. And we can hit Run. Next up, finally, we have the getActionItems function. So this is the final function, which retrieves the action items from Lemur. And how it works is we pass our transcript to Lemur by calling transcript.lemur.actionItems to specifically retrieve action items because that's what we're looking for. Besides generating action items, Lemur can also do summarization as well as question and answering. So that can be something interesting to try out as well. So when we're passing a query to Lemur, it's best to provide some sort of context on what your transcript is about. So that is why I have included this context that this is a transcript of a call between a customer and a call center agent. And also, I've given it an answer format in which I expect an answer to be returned. So a topic header and followed by relevant action items. Once we've done that, we're going to create a return statement and hit Run. Next, we're going to run the cell by actually calling the sendToAPI function. And this time, we are going to be passing our audio file as input for it to analyze and generate all of the things that we need like sentiment analysis as well as the action items. Once that cell runs, we're going to print out the response from the API. So as you can see, the sentiment for this call was mostly negative. And Lemur has also helped us to generate a lot of important action items, which can be used as follow-up. So now that we have completed the three main functions that we require for the logic of our application, so we simply need to copy these three functions for it to run. To download this project file, all you have to do is click on the GitHub link in the description box. And you should be able to download the entire project file. And what we're going to be doing first is once you open that project file in VS Code, click on the terminal. And what we're first going to be doing is creating a virtual environment and downloading all the required Python libraries for this UI application. First off, we're going to be creating a virtual environment. And I'm going to be writing down this command to create a virtual environment. Once we have done that, type in this command to activate the virtual environment that we have just created. And once that is activated, you should see the name of your virtual environment right here at the beginning of your command line. And then what we're going to do is we're going to download all the required Python libraries, which is actually in the requirements.txt file. So just do pip install requirements.txt. So just do a pip install requirements.txt. And this will essentially just download all the Python libraries that we need to run our application. Once that is done, let's head over to our application file and click on AIbot.py. And this contains all the code for our application. So as of now, I have copied the exact same code that we have written in the Google Colab into our project file. The only differences that I've done is I've added self to each function through the beginning of each function as a parameter and also self over here as well. And once you have done that, it is ready to go. You can hit Run on the application to actually test this out. And here's our main application. You can go ahead and click Select Audio File Analysis. And I'm going to be selecting an audio file and click Open. And here we have the final results. So we have the overall sentiment analysis as negative since we have given a negative audio file. And also with the help of Lemur, we have managed to generate 18 different action items for customer service, the delivery process, for call monitoring, and dropshipping. And this was incredibly easy to code with the help of Lemur's framework and the API. Let us know what you thought about this video in the comments section below. And if you want to see more use cases for Lemur, you can check out the documentation page, which I'll be linking in the description box as well. Thank you guys for watching, and subscribe for more amazing AI content.

ai AI Insights
Summary

Generate a brief summary highlighting the main points of the transcript.

Generate
Title

Generate a concise and relevant title for the transcript based on the main themes and content discussed.

Generate
Keywords

Identify and highlight the key words or phrases most relevant to the content of the transcript.

Generate
Enter your query
Sentiments

Analyze the emotional tone of the transcript to determine whether the sentiment is positive, negative, or neutral.

Generate
Quizzes

Create interactive quizzes based on the content of the transcript to test comprehension or engage users.

Generate
{{ secondsToHumanTime(time) }}
Back
Forward
{{ Math.round(speed * 100) / 100 }}x
{{ secondsToHumanTime(duration) }}
close
New speaker
Add speaker
close
Edit speaker
Save changes
close
Share Transcript