Skip to content

Commit 24a38c7

Browse files
authored
Merge pull request #42 from jsingh811/new-features
New features
2 parents e3d6792 + 8df3e9f commit 24a38c7

File tree

10 files changed

+164
-229
lines changed

10 files changed

+164
-229
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,44 @@ convert_files_to_wav(dir_path, audio_format="mp4")
205205
206206
```
207207

208+
209+
## Audio cleaning
210+
211+
To remove low-activity regions from your audio clip, the following sample usage can be referred to.
212+
213+
```
214+
from pyAudioProcessing import clean
215+
216+
clean.remove_silence(
217+
<path to wav file>,
218+
output_file=<path where you want to store cleaned wav file>
219+
)
220+
```
221+
222+
## Audio visualization
223+
224+
To see time-domain view of the audios, and the spectrogram of the audios, please refer to the following sample usage.
225+
226+
```
227+
from pyAudioProcessing import plot
228+
229+
# spectrogram plot
230+
plot.spectrogram(
231+
<path to wav file>,
232+
show=True, # set to False if you do not want the plot to show
233+
save_to_disk=True, # set to False if you do not want the plot to save
234+
output_file=<path where you want to store spectrogram as a png>
235+
)
236+
237+
# time-series plot
238+
plot.time(
239+
<path to wav file>,
240+
show=True, # set to False if you do not want the plot to show
241+
save_to_disk=True, # set to False if you do not want the plot to save
242+
output_file=<path where you want to store the plot as a png>
243+
)
244+
```
245+
208246
## Author
209247

210248
Jyotika Singh

paper/gfcc.png

-91.8 KB
Binary file not shown.

paper/mfcc.png

-57.4 KB
Binary file not shown.

paper/paper.bib

Lines changed: 0 additions & 102 deletions
This file was deleted.

paper/paper.md

Lines changed: 0 additions & 124 deletions
This file was deleted.

pyAudioProcessing/clean.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Thu Jun 10 15:23:55 2021
5+
6+
@author: jsingh
7+
"""
8+
# Imports
9+
import os
10+
import numpy
11+
from scipy.io import wavfile
12+
from pyAudioProcessing.utils import read_audio
13+
14+
# Globals
15+
LOW_PT_THRESHOLD = 0.01
16+
17+
# Functions
18+
19+
def remove_silence(
20+
input_file, output_file="without_sil.wav", thr=LOW_PT_THRESHOLD
21+
):
22+
"""
23+
Remove silences from input audio file.
24+
"""
25+
sampling_rate, signal = read_audio(input_file)
26+
signal = numpy.array(
27+
[
28+
list(i)
29+
for i in signal
30+
if not numpy.all((i == 0))
31+
]
32+
)
33+
mean_signal = [numpy.mean(list(i)) for i in signal]
34+
thrs_p = thr * max(mean_signal)
35+
thrs_n = thr * min(mean_signal)
36+
signal = numpy.array(
37+
[
38+
list(i)
39+
for i in signal
40+
if numpy.all((i > thrs_p)) or numpy.all((i < thrs_n))
41+
]
42+
)
43+
wavfile.write(output_file, sampling_rate, signal)
44+
45+

0 commit comments

Comments
 (0)