Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, descrevemos como usar o Speech-to-Text para detectar
automaticamente palavras obscenas nos seus dados de áudio e censurá-las na transcrição.
Para ativar o filtro de linguagem obscena, defina profanityFilter=true no
RecognitionFeatures.
Se ativado, o Speech-to-Text tentará detectar palavras obscenas e retornará
apenas a primeira letra seguida por asteriscos na transcrição (por exemplo,
f***). Se este campo estiver definido como false ou não for definido, o Speech-to-Text não
tentará filtrar a linguagem obscena.
Veja no exemplo a seguir como ativar o filtro de linguagem obscena
para reconhecer o áudio armazenado em um bucket do Cloud Storage.
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
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-02 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"]]