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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 3, 2025

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

      June 3, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 3, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 3, 2025

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 2025

      These solid-state fans will revolutionize cooling in our PCs and laptops

      June 3, 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

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025
      Recent

      Community News: Latest PECL Releases (06.03.2025)

      June 3, 2025

      A Comprehensive Guide to Azure Firewall

      June 3, 2025

      Test Job Failures Precisely with Laravel’s assertFailedWith Method

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

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025
      Recent

      All the WWE 2K25 locker codes that are currently active

      June 3, 2025

      PSA: You don’t need to spend $400+ to upgrade your Xbox Series X|S storage

      June 3, 2025

      UK civil servants saved 24 minutes per day using Microsoft Copilot, saving two weeks each per year according to a new report

      June 3, 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

    Security

    BitoPro Silent on $11.5M Hack: Investigator Uncovers Massive Crypto Theft

    June 3, 2025
    Security

    New Linux Vulnerabilities

    June 3, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Debunking MongoDB Myths: Security, Scale, and Performance

    Databases

    CVE-2025-47768 – Cisco ASA SSL/TLS Certificate Pinning Bypass

    Common Vulnerabilities and Exposures (CVEs)

    Working with Laravel’s Uri Class for Enhanced URL Manipulation

    Development

    How to Use WPScan to Keep Your WordPress Site Secure

    Development

    Highlights

    Development

    Meet Mini-Jamba: A 69M Parameter Scaled-Down Version of Jamba for Testing and Has the Simplest Python Code Generation Capabilities

    April 3, 2024

    In artificial intelligence, models are constantly sought to generate code accurately and efficiently. These models…

    CVE-2025-47641 – Printcart Web to Print Product Designer for WooCommerce Unrestricted File Upload Vulnerability

    May 26, 2025

    Once Human FAQ: Release date, platforms, price, and other questions answered

    July 4, 2024

    Sprinklr improves performance by 20% and reduces cost by 25% for machine learning inference on AWS Graviton3

    June 11, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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