Filter profanity from audio information utilizing Python

Filter profanity from audio information utilizing Python

Filter profanity from audio files using Python

With a better quantity of on-line interplay taking place day-after-day, it’s develop into more and more troublesome to make sure that these interactions are protected and constructive. Profanity filtering is a typical method used for this function throughout numerous purposes, from social media to buyer assist. Profanity detection synthetic intelligence fashions now allow builders to routinely and effectively filter out offensive language at scale, facilitating the event of protected and welcoming digital environments.

In this tutorial, we’ll learn to use Python to filter profanity from audio information. By the tip of this information, you may be geared up to implement this performance in just some traces of code, enhancing each person expertise and content material compliance.

Here is the audio file we might be operating profanity filtering on, together with the filtered output, the place the asterisks signify dangerous speech that has routinely been filtered:

Filter profanity from audio files using Python

Profanity filtering
0:00

/4.257938
Filtering profanity from audio and video information is straightforward as s*** with AssemblyAI.

Step 1: Set up your atmosphere

First, make certain Python is put in in your system if it isn’t already. Then, set up the assemblyai bundle, which permits builders to simply use AssemblyAI’s API.

pip set up assemblyai

Next, get a free AssemblyAI API key right here; or, if you have already got one, you’ll be able to copy it out of your Dashboard. Once you’ve copied your API key, set it as an atmosphere variable in your machine, which permits your requests to be routinely approved while you use the assemblyai bundle:

# Mac/Linux:
export ASSEMBLYAI_API_KEY=<YOUR_KEY>

# Windows:
set ASSEMBLYAI_API_KEY=<YOUR_KEY>

Step 2: Transcribe and filter the audio file

Now that the environment is about up, we will submit an audio file for transcription with profanity filtering. For this tutorial, we’ll be utilizing this instance file. If you wish to use your personal file, you should use both an area file in your system or a distant file so long as it’s a publicly accessible obtain URL (while you click on the hyperlink, it ought to begin downloading in your browser). You can both an audio or a video file.

Create a file referred to as foremost.py, after which import the assemblyai bundle and specify the trail to the audio file you wish to filter profanity from:

import assemblyai as aai

# change with native filepath or your distant file
audio_url = "https://storage.googleapis.com/aai-web-samples/profanity-filtering.mp3"

Next, we create an aai.TranscriptionConfig object, during which we specify the settings for our transcription. In this case, we allow profanity filtering by way of filter_profanity=True. Then we create an aai.Transcriber object, which truly performs transcription. Passing this config into the aai.Transcriber causes it to use profanity filtering to any file it transcribes.

config = aai.TranscriptionConfig(filter_profanity=True)
transcriber = aai.Transcriber(config=config)

Finally, we use the transcribe technique of the Transcriber object to transcribe the audio file with profanity filtering:

transcript = transcriber.transcribe(audio_url)

Step 3: Print the filtered textual content

We can print the profanity-filtered textual content as follows:

if not transcript.error:
    print(transcript.textual content)
else:
    increase RuntimeError(f"There was an error transcribing the file: {transcript.error}")

Save your file and execute it by operating python foremost.py within the undertaking listing. You’ll see the profanity-filtered audio transcript printed to the terminal – in the event you used the default file from above you’ll see the next output printed to the terminal:

Filtering profanity from audio and video information is straightforward as s*** with AssemblyAI.

The transcript comprises a litany of details about the transcribed audio file, like word-level timestamps and extra, which you’ll entry by the item’s attributes. Check out our docs to be taught extra about Transcript objects and the opposite data you will get again from our API.

Alternatively, be at liberty to take a look at our weblog for extra studying sources and tutorials, like this video on how one can construct a speaking AI with LLaMa 3:

HI-FI News

by way of News, Tutorials, AI Research https://ift.tt/j3Zpan2

May 22, 2024 at 07:00PM