Reputation: 31
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
Reputation: 6369
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.
Example:
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