Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to use Speech-to-Text to automatically detect
profane words in your audio data and censor them in the transcript.
You can enable the profanity filter by setting profanityFilter=true in
the RecognitionFeatures.
If enabled, Speech-to-Text will attempt to detect profane words and return
only the first letter followed by asterisks in the transcript (for example,
f***). If this field is set to false or not set, Speech-to-Text will
not attempt to filter profanities.
The following sample demonstrates how to enable the profanity filter to
recognize audio stored in a Cloud Storage bucket.
fromgoogle.cloudimportspeechfromgoogle.cloud.speechimportRecognizeResponsedefsync_recognize_with_profanity_filter_gcs(audio_uri:str)-> RecognizeResponse:"""Recognizes speech from an audio file in Cloud Storage and filters out profane language. Args: audio_uri (str): The Cloud Storage URI of the input audio, e.g., gs://[BUCKET]/[FILE] Returns: cloud_speech.RecognizeResponse: The full response object which includes the transcription results. """# Define the audio sourceaudio={"uri":audio_uri}client=speech.SpeechClient()config=speech.RecognitionConfig(encoding=speech.RecognitionConfig.AudioEncoding.FLAC,# Audio formatsample_rate_hertz=16000,language_code="en-US",# Enable profanity filterprofanity_filter=True,)response=client.recognize(config=config,audio=audio)forresultinresponse.results:alternative=result.alternatives[0]print(f"Transcript: {alternative.transcript}")returnresponse.results
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Enable the profanity filter\n\nThis page describes how to use Speech-to-Text to automatically detect\nprofane words in your audio data and censor them in the transcript.\n\nYou can enable the profanity filter by setting `profanityFilter`=`true` in\nthe [`RecognitionFeatures`](/speech-to-text/v2/docs/reference/rest/v2/projects.locations.recognizers#recognitionfeatures).\nIf enabled, Speech-to-Text will attempt to detect profane words and return\nonly the first letter followed by asterisks in the transcript (for example,\nf\\*\\*\\*). If this field is set to `false` or not set, Speech-to-Text will\nnot attempt to filter profanities.\n\nThe following sample demonstrates how to enable the profanity filter to\nrecognize audio stored in a Cloud Storage bucket. \n\n### Python\n\n\nTo learn how to install and use the client library for Speech-to-Text, see\n[Speech-to-Text client libraries](/speech-to-text/docs/client-libraries).\n\n\nFor more information, see the\n[Speech-to-Text Python API\nreference documentation](/python/docs/reference/speech/latest).\n\n\nTo authenticate to Speech-to-Text, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.cloud import speech\n from google.cloud.speech import RecognizeResponse\n\n\n def sync_recognize_with_profanity_filter_gcs(audio_uri: str) -\u003e RecognizeResponse:\n \"\"\"Recognizes speech from an audio file in Cloud Storage and filters out profane language.\n Args:\n audio_uri (str): The Cloud Storage URI of the input audio, e.g., gs://[BUCKET]/[FILE]\n Returns:\n cloud_speech.RecognizeResponse: The full response object which includes the transcription results.\n \"\"\"\n # Define the audio source\n audio = {\"uri\": audio_uri}\n\n client = speech.SpeechClient()\n config = speech.https://cloud.google.com/python/docs/reference/speech/latest/google.cloud.speech_v1.types.RecognitionConfig.html(\n encoding=speech.RecognitionConfig.AudioEncoding.FLAC, # Audio format\n sample_rate_hertz=16000,\n language_code=\"en-US\",\n # Enable profanity filter\n profanity_filter=True,\n )\n\n response = client.https://cloud.google.com/python/docs/reference/speech/latest/google.cloud.speech_v1.services.speech.SpeechClient.html#google_cloud_speech_v1_services_speech_SpeechClient_recognize(config=config, audio=audio)\n\n for result in response.results:\n alternative = result.alternatives[0]\n print(f\"Transcript: {alternative.transcript}\")\n\n return response.results\n\n\u003cbr /\u003e"]]