Automatically redact PII from audio and video with Python

Personal Identifiable Information, or PII, is details about a person that may be linked to that particular person in an identifiable method. How and by whom PII is dealt with and accessed is regulated by legal guidelines similar to HIPAA, GDPR, and CCPA.
Redacting PII from video or audio recordsdata (for instance, a physician/affected person go to) is a quite common want. Luckily, we are able to use AI to simply redact PII at scale.
In this tutorial, we’ll discover ways to redact a variety of PII classes, like medical circumstances, e mail addresses, and bank card numbers, from audio and video recordsdata in addition to their textual transcripts. Here you may see the ultimate redacted transcript we’ll create, in addition to the related redacted audio file:
Good afternoon, MGK design. Hi. I'm trying to have plans drawn up for an addition in my home. Okay, let me have one in every of our architects return your name. May I've your identify, please? My identify is ####. ####. And your final identify? My final identify is #####. Would you spell that for me, please? # # # # # #. Okay, and your phone quantity? Area code? ###-###-#### that is ###-###-#### sure, ma'am. Is there a very good time to succeed in you? That's my cell, so he may catch me anytime on that. Okay, nice. I'll have him return your name as quickly as attainable. Great. Thank you very a lot. You're welcome. Bye.
Code referring to this tutorial will be present in this GitHub repository. Let’s get began!
Step 1: Set up surroundings
First, create a undertaking listing and navigate into it. Then, create a digital surroundings:
# Mac/Linux:
python3 -m venv venv
. venv/bin/activate
# Windows:
python -m venv venv
.venvScriptsactivate.bat
Next, set up the AssemblyAI Python SDK:
pip set up assemblyai
Then set your AssemblyAI API Key as an surroundings variable. You can get an AssemblyAI API key right here totally free. Note that you’re going to want so as to add funds to transcend Speech Recognition and use our Audio Intelligence fashions like PII Redaction.
# Mac/Linux:
export ASSEMBLYAI_API_KEY=<YOUR_KEY>
# Windows:
set ASSEMBLYAI_API_KEY=<YOUR_KEY>
Step 2: Transcribe the file
Now that our surroundings is ready up, we are able to submit an audio file for transcription. For this tutorial, we’ll use a quick telephone dialog between a person and an structure agency. First, we’ll import the AssemblyAI Python SDK, after which specify the publicly-accessible URL of our audio file (you too can use a video file). Create a file referred to as fundamental.py and add the next strains:
import assemblyai as aai
audio_url = "https://storage.googleapis.com/aai-web-samples/architecture-call.mp3"
Next, we have to configure our transcription to redact PII, and set the kinds of PII we need to redact. We specify this in an aai.TranscriptionConfig. Add the next strains to fundamental.py:
config = aai.TranscriptionConfig(
redact_pii=True,
redact_pii_audio=True,
redact_pii_policies=[
aai.PIIRedactionPolicy.person_name,
aai.PIIRedactionPolicy.phone_number,
],
redact_pii_sub=aai.PIISubstitutionPolicy.hash,
)
We allow PII Redaction via redact_pii, and specify that we additionally need a redacted model of the audio file itself (along with the redacted transcript) via redact_pii_audio.
Then, we set the classes, or insurance policies, of PII we need to redact via redact_pii_policies. For a listing of all out there insurance policies, see PII insurance policies in our docs. Finally, we set how the PII is redacted via redact_pii_sub. In this case, we use a hash such that redacted audio is changed with a sequence of hashes (####). You can discover the attainable values for this parameter within the PII Redaction API reference in our docs.
Now we are able to transcribe the audio file through the use of the transcribe technique of an aai.Transcriber, passing within the configuration we simply created. Add the next line to fundamental.py:
transcript = aai.Transcriber().transcribe(audio_url, config)
Step 3: Print the redacted transcript
When this system executes, the transcribe technique submits the file for transcription. The ensuing transcript is on the market via transcript.textual content. Add a line to fundamental.py to print out the redacted transcript once we execute this system:
print(transcript.textual content, 'nn')
Step 4: Fetch the redacted audio recordsdata
You can print off the URL of the redacted audio file by including the beneath line to fundamental.py
print(transcript.get_redacted_audio_url())
Step 5: Run this system
In a terminal (together with your AssemblyAI API key set as an surroundings variable as proven in Step 2), execute python fundamental.py or python3 fundamental.py to run this system. After a couple of moments, the redacted transcript shall be printed:
Good afternoon, MGK design. Hi. I'm trying to have plans drawn up for an addition in my home. Okay, let me have one in every of our architects return your name. May I've your identify, please? My identify is ####. ####. And your final identify? My final identify is #####. Would you spell that for me, please? # # # # # #. Okay, and your phone quantity? Area code? ###-###-#### that is ###-###-#### sure, ma'am. Is there a very good time to succeed in you? That's my cell, so he may catch me anytime on that. Okay, nice. I'll have him return your name as quickly as attainable. Great. Thank you very a lot. You're welcome. Bye.
As we are able to see, the desired PII sorts have been redacted within the transcript. You can see the unredacted transcript beneath for comparability:
Good afternoon, MGK design. Hi. I'm trying to have plans drawn up for an addition in my home. Okay, let me have one in every of our architects return your name. May I've your identify, please? My identify is John. John. And your final identify? My final identify is Lowry. Would you spell that for me, please? L o w e r y. Okay, and your phone quantity? Area code? 610-265-1714 that is 610-265-1714 sure, ma'am. Is there a very good time to succeed in you? That's my cell, so he may catch me anytime on that. Okay, nice. I'll have him return your name as quickly as attainable. Great. Thank you very a lot. You're welcome. Bye.
Finally, the URL of your redacted audio file shall be printed to the console. Go to the URL, and also you’ll be capable of obtain the redacted audio file:
Note {that a} redacted audio file shall be returned, even if you happen to submitted a video file for transcription. In this case, you should use a device like FFmpeg to switch the unique audio within the file with the redacted model.
Optionally, you may take a look at the code in examine.py within the undertaking repository to print the variations between the unredacted and redacted variations of the transcript.
Final phrases
In this tutorial, we discovered find out how to robotically redact PII from audio and video recordsdata in 5 minutes utilizing AssemblyAI and Python. You can take a look at our docs on PII redaction to be taught extra about it or browse a few of our different AI fashions.
Alternatively, be at liberty to take a look at our weblog or YouTube channel for academic content material on AI and Machine Learning, like this video on find out how to construct an AI voice bot with Python:
HI-FI News
by way of News, Tutorials, AI Research https://ift.tt/3QRj9sX
March 18, 2024 at 04:29PM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








