Skip to content

Commit

Permalink
Merge pull request #42 from jsingh811/new-features
Browse files Browse the repository at this point in the history
New features
  • Loading branch information
jsingh811 authored Jul 20, 2021
2 parents e3d6792 + 8df3e9f commit 24a38c7
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 229 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,44 @@ convert_files_to_wav(dir_path, audio_format="mp4")
```


## Audio cleaning

To remove low-activity regions from your audio clip, the following sample usage can be referred to.

```
from pyAudioProcessing import clean
clean.remove_silence(
<path to wav file>,
output_file=<path where you want to store cleaned wav file>
)
```

## Audio visualization

To see time-domain view of the audios, and the spectrogram of the audios, please refer to the following sample usage.

```
from pyAudioProcessing import plot
# spectrogram plot
plot.spectrogram(
<path to wav file>,
show=True, # set to False if you do not want the plot to show
save_to_disk=True, # set to False if you do not want the plot to save
output_file=<path where you want to store spectrogram as a png>
)
# time-series plot
plot.time(
<path to wav file>,
show=True, # set to False if you do not want the plot to show
save_to_disk=True, # set to False if you do not want the plot to save
output_file=<path where you want to store the plot as a png>
)
```

## Author

Jyotika Singh
Expand Down
Binary file removed paper/gfcc.png
Binary file not shown.
Binary file removed paper/mfcc.png
Binary file not shown.
102 changes: 0 additions & 102 deletions paper/paper.bib

This file was deleted.

124 changes: 0 additions & 124 deletions paper/paper.md

This file was deleted.

45 changes: 45 additions & 0 deletions pyAudioProcessing/clean.py
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)


Loading

0 comments on commit 24a38c7

Please sign in to comment.