-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from jsingh811/new-features
New features
- Loading branch information
Showing
10 changed files
with
164 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Thu Jun 10 15:23:55 2021 | ||
@author: jsingh | ||
""" | ||
# Imports | ||
import os | ||
import numpy | ||
from scipy.io import wavfile | ||
from pyAudioProcessing.utils import read_audio | ||
|
||
# Globals | ||
LOW_PT_THRESHOLD = 0.01 | ||
|
||
# Functions | ||
|
||
def remove_silence( | ||
input_file, output_file="without_sil.wav", thr=LOW_PT_THRESHOLD | ||
): | ||
""" | ||
Remove silences from input audio file. | ||
""" | ||
sampling_rate, signal = read_audio(input_file) | ||
signal = numpy.array( | ||
[ | ||
list(i) | ||
for i in signal | ||
if not numpy.all((i == 0)) | ||
] | ||
) | ||
mean_signal = [numpy.mean(list(i)) for i in signal] | ||
thrs_p = thr * max(mean_signal) | ||
thrs_n = thr * min(mean_signal) | ||
signal = numpy.array( | ||
[ | ||
list(i) | ||
for i in signal | ||
if numpy.all((i > thrs_p)) or numpy.all((i < thrs_n)) | ||
] | ||
) | ||
wavfile.write(output_file, sampling_rate, signal) | ||
|
||
|
Oops, something went wrong.