Faisal Ryan
Faisal Ryan

Reputation: 31

recognize_google(audio) filters out bad words

I'm facing this problem with google speech_recognition api. It automatically filters out bad words and returns a string like "F***" or "P******"

Here is my code. There is no error in my code but please help how do I get a raw converted text from my audio.

    from gtts import gTTS
    import speech_recognition as sr

    r = sr.Recognizer()

with sr.Microphone() as source:
    print('Ready...')
    r.pause_threshold = 1
    r.adjust_for_ambient_noise(source, duration=1)
    audio = r.listen(source)

    command = r.recognize_google(audio).lower()
    print('You said: ' + command + '\n')

Upvotes: 2

Views: 2627

Answers (1)

handle
handle

Reputation: 6369

profanity_filter

Optional If set to true, the server will attempt to filter out profanities, replacing all but the initial character in each filtered word with asterisks, e.g. “f***”. If set to false or omitted, profanities won’t be filtered out.

Search: https://googlecloudplatform.github.io/google-cloud-python/latest/search.html?q=profanity_filter&check_keywords=yes&area=default

Example:

https://googlecloudplatform.github.io/google-cloud-python/latest/speech/index.html?highlight=profanity_filter#synchronous-recognition

Example of using the profanity filter.

>>> from google.cloud import speech
>>> client = speech.SpeechClient()
>>> results = client.recognize(
...     audio=speech.types.RecognitionAudio(
...         uri='gs://my-bucket/recording.flac',
...     ),
...     config=speech.types.RecognitionConfig(
...         encoding='LINEAR16',
...         language_code='en-US',
...         profanity_filter=True,
...         sample_rate_hertz=44100,
...     ),
... )
>>> for result in results:
...     for alternative in result.alternatives:
...         print('=' * 20)
...         print('transcript: ' + alternative.transcript)
...         print('confidence: ' + str(alternative.confidence))
====================
transcript: Hello, this is a f****** test
confidence: 0.81

Nice example ;-)

(I have not tested this)

Upvotes: 5

Related Questions