Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan cara menggunakan Speech-to-Text untuk secara otomatis mendeteksi kata-kata tidak sopan dalam data audio Anda dan menyensornya dalam transkrip.
Anda dapat mengaktifkan filter kata-kata tidak sopan dengan menetapkan profanityFilter=true di RecognitionFeatures.
Jika diaktifkan, Speech-to-Text akan mencoba mendeteksi kata-kata tidak sopan dan hanya menampilkan huruf pertama yang diikuti dengan tanda bintang dalam transkrip (misalnya f***). Jika kolom ini ditetapkan ke false atau tidak ditetapkan, Speech-to-Text tidak akan
mencoba memfilter kata-kata tidak sopan.
Contoh berikut menunjukkan cara mengaktifkan filter kata-kata tidak sopan untuk mengenali audio yang disimpan di bucket 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
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 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"]]