Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite wird beschrieben, wie Sie mit Speech-to-Text anstößige Wörter in Ihren Audiodaten automatisch erkennen und im Transkript zensieren.
Sie können den Filter für vulgäre Ausdrücke aktivieren, indem Sie RecognitionFeaturesprofanityFilter=true festlegen.
Wenn diese Option aktiviert ist, versucht Speech-to-Text, anstößige Wörter zu erkennen und nur den ersten Buchstaben gefolgt von Sternchen im Transkript zurückzugeben (z. B. f***). Wenn dieses Feld auf false festgelegt oder nicht festgelegt ist, versucht Speech-to-Text nicht, Obszönitäten zu filtern.
Im folgenden Beispiel wird gezeigt, wie der Obszönitätenfilter aktiviert wird, um in einem Cloud Storage-Bucket gespeicherte Audiodaten zu erkennen.
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
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (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"]]