Clean audio
Zeroing out segments from a tsv
import torchaudio
# this assumes audacity-style tsv: start, end, text
def read_tsv(filename):
times = []
with open(filename) as tsvf:
for line in tsvf.readlines():
line = line.strip()
if not "\t" in line:
continue
parts = line.split("\t")
times.append((parts[0], parts[1]))
return times
def clean_audio_from_list(wavfile, outputwav, times):
waveform, sample_rate = torchaudio.load(wavfile)
for time in times:
start = int(time[0] * sample_rate)
end = int(time[1] * sample_rate)
waveform[:, start:end] = 0.0
torchaudio.save(outputwav, waveform, sample_rate)
input = "/Users/joregan/Playing/hsi/audio/hsi_5_0718_210_003_main.wav"
output = "/tmp/clean.wav"
dummy = [
(15.360, 15.835),
(41.120, 42.115),
(76.211, 76.840),
(455.737, 455.845)
]
clean_audio_from_list(input, output, dummy)