I have a audio file 'sample.wav' and I am trying to mask timestamp 1:00-1:20 of the audio. The output audio would be the original audio with the 1:00-1:20 timespan silent. I am running the following code but no masking is happening.
import soundfile as sf
import torch
# Load the audio file
audio_path = 'sample.wav'
waveform, sample_rate = sf.read(audio_path)
# Define the start and end indices of the segments you want to mask (in seconds)
start_time = 1.0
end_time = 1.20
# Convert time to samples
start_sample = int(start_time * sample_rate)
end_sample = int(end_time * sample_rate)
# Apply mask to the segment
waveform[start_sample:end_sample] = 0 # Zeroing out the segment
output_path = "masked_audio.wav"
sf.write(output_path, waveform, sample_rate)
ok it worked when i used the
pydubpackage for audio manipulation