How to do content moderation on audio files in Python

AssemblyAI · Beginner ·🧠 Large Language Models ·4y ago

Key Takeaways

This video teaches how to do content moderation on audio files in Python

Full Transcript

hello and welcome today we are going to learn how to moderate what is being said in audio files in python so this is what our results are going to look like here we have a list of parts of this audio file where something is being said that might need to be moderated out we get the text of what is being said we have the confidence level for this label what kind of uh problem there might be with this part of the audiophile and the severity of what is being uttered so here it says crime and violence but the severity is very low so maybe if it was 0.9 there could be something about crime or violence that could be very disturbing to the listeners so let's build this so to achieve the content moderation in this project we are going to use assembly ai assembly ai has some audio intelligence features and content moderation is one of them and that gives us the results that we've just seen so to do that first we need an assembly ai api token so let's go get that you can either use the link in the description or you can go to assemblyai.com create an account through get started and once you have an account you will be automatically assigned a free api token that you can copy right from here and here in our project we have a main file where we're going to have the actual code and in the configure file i'm going to keep my assembly ai authentication key and once i've done that of course i also want to import it here and to talk to assembly ai we are going to need to use the requests library and it's actually very simple to start a transcription or audio intelligence job with assembly ai all we have to do is to send a post request inside this post request we are going to need three things the first one is the endpoint of course this is the endpoint that we are sending the request to and we are going to use the transcription endpoint of assembly ai and the next thing that we're going to need is the data that we're sending to assembly ai you can either upload your data or your audio file to assembly ai or if you like you can upload it somewhere else and just pass the url to assembly ai which will be a faster way of doing it so that's how we're going to do it and it's going to be in json format so i'll also just call the variable json to keep things simple so the first thing that i need to pass is the order url and also in here i want to include what i want assembly ai to do on top of the transcription and here we want to do content moderation so we want to turn the content safety feature of assembly ai on because normally if you don't specifically tell them to be true it by default is false all of the content miteration sentiment analysis and all basically all audio intelligence features are by default turned off so once we did that the next thing that we want to include are the headers headers are going to help us authenticate ourselves with the authentication key that we have so let's set that up the first thing that we need of course is the authentication key and the second thing that we need is to tell assembly ai what kind of content we're sending its way and here we are sending a json format and this is all to start a transcription job so let's see what assembly ai what kind of response assembly ai sends to us and then we can understand what we need to do next all right so this is the result we get from assembly ai it includes some information that we need for example the id this is the id of the transcription job or audio intelligence job that has been started we also have some other information like the language model that is being used or what kind of features are turned on so as you can see sentiment analysis entity detection and everything else is turned off and what we want is the content safety so let's see content safety is turned on so that's what we wanted now using this id we can actually ask assembly ai when the transcription or audio intelligence job is done and get the results so for that i'm going to create a while loop inside this while loop what i want to do is ask assembly ai if transcription is done and if the answer is yes print results so to do that we are going to continuously have to ask assembly ai if the result is done so i would create a function where i do exactly that and to inside this function we are going to need to create a specific endpoint for our transcription job that endpoint is going to consist of the endpoint that we have already and a transcription id the transcription id we are going to get from the result of uh the submission of the transcription so let the one that we saw here this is the id so very simply it will just be response.json id all right this will be the polling endpoint and once we have the polling endpoint what we're going to do is again to use the request library and send a get request because we are not actually sending any information any data all we're doing is to ask for data and we are going to send it to the polling endpoint and i'm going to include the headers again for authentication of course as a result we are going to get a polling response this response is going to tell us whether the transcription is done or not you can already actually see it here if i look for status status is queued immediately after you send it it turns into processing and then after a while it is completed or if it's not completed if there was an error then it errors out and once we get the polling response we can actually return the polling response here with the information and i will call that function here actually of course this needs a transcription id and here i would need to call it with the transcription id and the resulting thing that we get i'll just call it data for now so just as we've seen here we have the status so here to see if the transcription is done or not i would have to see if data status is completed or not and if it has been completed then we can print the data so we're doing that here we'll be doing that too uh what else we want to include we also want to see if the transcription has errored out we want to warn the user about that so i'll just save the status as is error then we are going to print for example there was an error and we can also print the error section of our results just to kind of see what went wrong in there so that's basically it that's all we need to do just something that i want to fix here is instead of just printing it i actually want to use pretty print so that we can understand what's happening a little bit better because we're going to get a lot of information and also i would like to add some waiting time in between asking assembly ai if the transcription is done because otherwise we're just constantly asking and there is not really a good use for it so we'll just say time sleep 30 seconds and we can say before we sleep print waiting for 30 seconds so that's all we have to do actually one thing that i forgot is that we need a slash here to build the url properly and that's all that's all we need to do to ask send assembly ai the content moderation job and then wait for it and get the results so let's run this and see what the results are looking like we got the confirmation that the transcription job has been started we have an id for it and now we're going to probably wait a couple of minutes before we get the results all right our transcription is done but i've just realized that i forgot to stop the while loop here so i'll just need to add some breaks here once we get a result or one set error is out uh so and i i will just stop this one but we have the results so let's go through the results and see what they look like uh yeah so this is what we get from assembly ai as we also seen before we have the text of what is being said when there was something that that might need to be moderated the severity of the situation and what kind of thing this uh what kind of label or class that this text belongs to here we got for example health issues we got profanity uh we got health issues again so i guess this talk was a lot about health issues so we got a lot of it so basically um by using assembly ai's api here with the audio intelligence you get the information of where this sentences that might be problematic was talked uh on or what what it was and also when so you have the start and ending timestamps of when this part was talked about and that's basically it if you have any questions about how we build this project or how to use assembly ai's api don't forget to leave a comment in the description below and before you leave don't forget to go get your free assembly ai api token either using the link in the description or by going to assemblyai.com thanks for watching and i will see you in the next video [Music] you

Original Description

Sometimes audio data includes sensitive/hurtful content. Before publishing a piece of work this might need to be edited out or a warning message might need to be added. It is, however, really costly and inefficient to detect this by listening to the audio file. Instead, you can use Python and AssemblyAI's API to find out if the audio includes any sensitive content. Let's find out how to do it in this video! Get your Free Token for AssemblyAI Speech-To-Text API 👇https://www.assemblyai.com/?utm_source=youtube&utm_medium=referral&utm_campaign=yt_mis_31 ▬▬▬▬▬▬▬▬▬▬▬▬ CONNECT ▬▬▬▬▬▬▬▬▬▬▬▬ 🖥️ Website: https://www.assemblyai.com 🐦 Twitter: https://twitter.com/AssemblyAI 🦾 Discord: https://discord.gg/Cd8MyVJAXd ▶️ Subscribe: https://www.youtube.com/c/AssemblyAI?sub_confirmation=1 🔥 We're hiring! Check our open roles: https://www.assemblyai.com/careers ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ #MachineLearning #DeepLearning
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from AssemblyAI · AssemblyAI · 0 of 60

← Previous Next →
1 Python Speech Recognition in 5 Minutes
Python Speech Recognition in 5 Minutes
AssemblyAI
2 Python Click Part 1 of 4
Python Click Part 1 of 4
AssemblyAI
3 Python Click Part 2 of 4
Python Click Part 2 of 4
AssemblyAI
4 Python Click Part 3 of 4
Python Click Part 3 of 4
AssemblyAI
5 Python Click Part 4 of 4
Python Click Part 4 of 4
AssemblyAI
6 Deep learning in 5 minutes | What is deep learning?
Deep learning in 5 minutes | What is deep learning?
AssemblyAI
7 How to make a web app that transcribes YouTube videos with Streamlit | Part 1
How to make a web app that transcribes YouTube videos with Streamlit | Part 1
AssemblyAI
8 How to make a web app that transcribes YouTube videos with Streamlit | Part 2
How to make a web app that transcribes YouTube videos with Streamlit | Part 2
AssemblyAI
9 Batch normalization | What it is and how to implement it
Batch normalization | What it is and how to implement it
AssemblyAI
10 Real-time Speech Recognition in 15 minutes with AssemblyAI
Real-time Speech Recognition in 15 minutes with AssemblyAI
AssemblyAI
11 Regularization in a Neural Network | Dealing with overfitting
Regularization in a Neural Network | Dealing with overfitting
AssemblyAI
12 Add speech recognition to your Streamlit apps in 5 minutes
Add speech recognition to your Streamlit apps in 5 minutes
AssemblyAI
13 Transformers for beginners | What are they and how do they work
Transformers for beginners | What are they and how do they work
AssemblyAI
14 Automatic Chapter Detection With AssemblyAI | Python Tutorial
Automatic Chapter Detection With AssemblyAI | Python Tutorial
AssemblyAI
15 Deep Learning Series Part 1 - What is Deep Learning?
Deep Learning Series Part 1 - What is Deep Learning?
AssemblyAI
16 Deep Learning Series part 2 - Why is it called “Deep Learning”?
Deep Learning Series part 2 - Why is it called “Deep Learning”?
AssemblyAI
17 Activation Functions In Neural Networks Explained | Deep Learning Tutorial
Activation Functions In Neural Networks Explained | Deep Learning Tutorial
AssemblyAI
18 Deep Learning Series part 3 - Deep Learning vs. Machine Learning
Deep Learning Series part 3 - Deep Learning vs. Machine Learning
AssemblyAI
19 Deep Learning Series part 4 - Why is Deep Learning better for NLP?
Deep Learning Series part 4 - Why is Deep Learning better for NLP?
AssemblyAI
20 Intro to Batch Normalization Part 1
Intro to Batch Normalization Part 1
AssemblyAI
21 Intro to Batch Normalization Part 2
Intro to Batch Normalization Part 2
AssemblyAI
22 Intro to Batch Normalization Part 3 - What is Normalization?
Intro to Batch Normalization Part 3 - What is Normalization?
AssemblyAI
23 Intro to Batch Normalization Part 4
Intro to Batch Normalization Part 4
AssemblyAI
24 Intro to Batch Normalization Part 5
Intro to Batch Normalization Part 5
AssemblyAI
25 Sentiment Analysis for Earnings Calls with AssemblyAI
Sentiment Analysis for Earnings Calls with AssemblyAI
AssemblyAI
26 Summarizing my favorite podcasts with Python
Summarizing my favorite podcasts with Python
AssemblyAI
27 Introduction to Regularization
Introduction to Regularization
AssemblyAI
28 How/Why Regularization in Neural Networks?
How/Why Regularization in Neural Networks?
AssemblyAI
29 Getting Started With Torchaudio | PyTorch Tutorial
Getting Started With Torchaudio | PyTorch Tutorial
AssemblyAI
30 Types of Regularization
Types of Regularization
AssemblyAI
31 Tuning Alpha in L1 and L2 Regularization
Tuning Alpha in L1 and L2 Regularization
AssemblyAI
32 Dropout Regularization
Dropout Regularization
AssemblyAI
33 What is GPT-3 and how does it work? | A Quick Review
What is GPT-3 and how does it work? | A Quick Review
AssemblyAI
34 Backpropagation For Neural Networks Explained | Deep Learning Tutorial
Backpropagation For Neural Networks Explained | Deep Learning Tutorial
AssemblyAI
35 Jupyter Notebooks Tutorial | How to use them & tips and tricks!
Jupyter Notebooks Tutorial | How to use them & tips and tricks!
AssemblyAI
36 Best Free Speech-To-Text APIs and Open Source Libraries
Best Free Speech-To-Text APIs and Open Source Libraries
AssemblyAI
37 Regularization - Early stopping
Regularization - Early stopping
AssemblyAI
38 Regularization - Data Augmentation
Regularization - Data Augmentation
AssemblyAI
39 Bias and Variance for Machine Learning | Deep Learning
Bias and Variance for Machine Learning | Deep Learning
AssemblyAI
40 Recurrent Neural Networks (RNNs) Explained - Deep Learning
Recurrent Neural Networks (RNNs) Explained - Deep Learning
AssemblyAI
41 What is BERT and how does it work? | A Quick Review
What is BERT and how does it work? | A Quick Review
AssemblyAI
42 Introduction to Transformers
Introduction to Transformers
AssemblyAI
43 Transformers | What is attention?
Transformers | What is attention?
AssemblyAI
44 Transformers | how attention relates to Transformers
Transformers | how attention relates to Transformers
AssemblyAI
45 Transformers | Basics of Transformers
Transformers | Basics of Transformers
AssemblyAI
46 Supervised Machine Learning Explained For Beginners
Supervised Machine Learning Explained For Beginners
AssemblyAI
47 Transformers | Basics of Transformers Encoders
Transformers | Basics of Transformers Encoders
AssemblyAI
48 Transformers | Basics of Transformers I/O
Transformers | Basics of Transformers I/O
AssemblyAI
49 How to evaluate ML models | Evaluation metrics for machine learning
How to evaluate ML models | Evaluation metrics for machine learning
AssemblyAI
50 Unsupervised Machine Learning Explained For Beginners
Unsupervised Machine Learning Explained For Beginners
AssemblyAI
51 Weight Initialization for Deep Feedforward Neural Networks
Weight Initialization for Deep Feedforward Neural Networks
AssemblyAI
52 Q-Learning Explained - Reinforcement Learning Tutorial
Q-Learning Explained - Reinforcement Learning Tutorial
AssemblyAI
53 Should You Use PyTorch or TensorFlow in 2022?
Should You Use PyTorch or TensorFlow in 2022?
AssemblyAI
54 What is Layer Normalization? | Deep Learning Fundamentals
What is Layer Normalization? | Deep Learning Fundamentals
AssemblyAI
55 I created a Python App to study FASTER
I created a Python App to study FASTER
AssemblyAI
56 How to create your FIRST NEURAL NETWORK with TensorFlow!
How to create your FIRST NEURAL NETWORK with TensorFlow!
AssemblyAI
57 Neural Networks Summary: All hyperparameters
Neural Networks Summary: All hyperparameters
AssemblyAI
58 Getting Started with OpenAI API and GPT-3 | Beginner Python Tutorial
Getting Started with OpenAI API and GPT-3 | Beginner Python Tutorial
AssemblyAI
59 Convert Speech-To-Text In Python in 60 seconds!
Convert Speech-To-Text In Python in 60 seconds!
AssemblyAI
60 Gradient Clipping for Neural Networks | Deep Learning Fundamentals
Gradient Clipping for Neural Networks | Deep Learning Fundamentals
AssemblyAI

Related Reads

📰
How Couchbase built a multi-model AI architecture for Capella iQ with Amazon Bedrock
Learn how Couchbase built a multi-model AI architecture for Capella iQ using Amazon Bedrock and Anthropic's Claude models
AWS Machine Learning
📰
Local GLM 4.7 from Z.ai on dual Nvidia RTX 3090: when the smarter model is the wrong pick
Learn when a smarter model like Local GLM 4.7 might not be the best choice for your hardware, and how to evaluate model performance in a home setup.
Dev.to AI
📰
Flowing vs. Thinking: How Liquid Neural Networks Diverge from LLMs
Learn how Liquid Neural Networks diverge from traditional LLMs in approach and application, and why this matters for robotics and continuous time problems
Dev.to AI
📰
Soofi provides sovereign open source foundation models. Designed for independent AI development. https://www.soofi.info/
Learn about Soofi, a platform providing sovereign open source foundation models for independent AI development
Dev.to AI
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →