pythonaudiospeech-recognitionaudio-processingaudio-analysis

How to silence specific words in an audio file using python?


I want to mute specific words in audio files. I have a list of words that should be muted. I have tried converting the audio file to text using this code but how can I get the time frame of each word so I can mute them?

import speech_recognition as sr 
import moviepy.editor as mp

r = sr.Recognizer()

audio = sr.AudioFile("Welcome.wav")
print(audio)

with audio as source:
  audio_file = r.record(source)
  print(audio_file)

try:
        # using google speech recognition
        text = r.recognize_google(audio_file)
        print('Converting audio transcripts into text ...')
        print(text)
     
except:
         print('Sorry.. run again...')

# exporting the result 
with open('recognized.txt',mode ='w') as file: 
   file.write("Recognized Speech:") 
   file.write("\n") 
   file.write(text) 
   print("ready!") 

Solution

  • This answer shows how to get the timestamps of words. The timestamps can then be used to silence sections containing the words to be muted.