Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

      June 1, 2025

      A week of hell with my Windows 11 PC really makes me appreciate the simplicity of Google’s Chromebook laptops

      June 1, 2025

      Elden Ring Nightreign Night Aspect: How to beat Heolstor the Nightlord, the final boss

      June 1, 2025

      New Xbox games launching this week, from June 2 through June 8 — Zenless Zone Zero finally comes to Xbox

      June 1, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

      June 1, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

      June 1, 2025
      Recent

      My top 5 must-play PC games for the second half of 2025 — Will they live up to the hype?

      June 1, 2025

      A week of hell with my Windows 11 PC really makes me appreciate the simplicity of Google’s Chromebook laptops

      June 1, 2025

      Elden Ring Nightreign Night Aspect: How to beat Heolstor the Nightlord, the final boss

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Artificial Intelligence»Filter profanity from audio files using Python

    Filter profanity from audio files using Python

    May 22, 2024

    With a greater amount of online interaction happening every day, it’s become increasingly difficult to ensure that these interactions are safe and constructive. Profanity filtering is a common technique used for this purpose across various applications, from social media to customer support. Profanity detection artificial intelligence models now enable developers to automatically and efficiently filter out offensive language at scale, facilitating the development of safe and welcoming digital environments.

    In this tutorial, we’ll learn how to use Python to filter profanity from audio files. By the end of this guide, you’ll be equipped to implement this functionality in just a few lines of code, enhancing both user experience and content compliance.

    Here is the audio file we will be running profanity filtering on, along with the filtered output, where the asterisks represent harmful speech that has automatically been filtered:

    Profanity filtering
    0:00
    /4.257938

    Filtering profanity from audio and video files is easy as s*** with AssemblyAI.

    Step 1: Set up your environment

    First, make sure Python is installed on your system if it is not already. Then, install the assemblyai package, which allows developers to easily use AssemblyAI’s API.

    pip install assemblyai

    Next, get a free AssemblyAI API key here; or, if you already have one, you can copy it from your Dashboard. Once you’ve copied your API key, set it as an environment variable on your machine, which allows your requests to be automatically authorized when you use the assemblyai package:

    # 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 our environment is set up, we can submit an audio file for transcription with profanity filtering. For this tutorial, we’ll be using this example file. If you want to use your own file, you can use either a local file on your system or a remote file as long as it is a publicly accessible download URL (when you click the link, it should start downloading in your browser). You can either an audio or a video file.

    Create a file called main.py, and then import the assemblyai package and specify the path to the audio file you want to filter profanity from:

    import assemblyai as aai

    # replace with local filepath or your remote file
    audio_url = “https://storage.googleapis.com/aai-web-samples/profanity-filtering.mp3”

    Next, we create an aai.TranscriptionConfig object, in which we specify the settings for our transcription. In this case, we enable profanity filtering via filter_profanity=True. Then we create an aai.Transcriber object, which actually performs transcription. Passing this config into the aai.Transcriber causes it to apply profanity filtering to any file it transcribes.

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

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

    transcript = transcriber.transcribe(audio_url)

    Step 3: Print the filtered text

    We can print the profanity-filtered text as follows:

    if not transcript.error:
    print(transcript.text)
    else:
    raise RuntimeError(f”There was an error transcribing the file: {transcript.error}”)

    Save your file and execute it by running python main.py in the project directory. You’ll see the profanity-filtered audio transcript printed to the terminal – if you used the default file from above you’ll see the following output printed to the terminal:

    Filtering profanity from audio and video files is easy as s*** with AssemblyAI.

    The transcript contains a litany of information about the transcribed audio file, like word-level timestamps and more, which you can access through the object’s attributes. Check out our docs to learn more about Transcript objects and the other information you can get back from our API.

    Alternatively, feel free to check out our blog for more learning resources and tutorials, like this video on how to build a talking AI with LLaMa 3:

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleDecoding the AI mind: Anthropic researchers peer inside the “black box”
    Next Article How Procurement Transformation can streamline your Procurement Processes

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    June 1, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    June 1, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    JetBrains announces a free tier for its AI tools

    Tech & Work

    How publishers use Figma to help design the news

    Web Development

    Wardrobe is a GNOME customization tool

    Linux

    Intelbroker Advertises Massive AMD Data Breach on Dark Web Forums

    Development

    Highlights

    PAR Scrape is a web scraping tool

    March 26, 2025

    PAR Scrape is a versatile web scraping tool with options for Selenium or Playwright, featuring…

    Behind the Code: A Discussion with Backend Experts including Taylor Otwell

    June 27, 2024

    Review your Amazon Aurora and Amazon RDS security configuration with Prowler’s new checks

    August 6, 2024

    After 25 Years, Linux Format Magazine is No More

    May 30, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.