Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2020-101
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sachith Fernando
2020-101
Commits
dc8d49fd
Commit
dc8d49fd
authored
Nov 05, 2020
by
I.K Seneviratne
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'IT17100908' into 'QA_RELEASE'
It17100908 See merge request
!28
parents
49a7fec1
53f420ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
49 deletions
+89
-49
LectureSummarizingApp/noise.py
LectureSummarizingApp/noise.py
+32
-49
LectureSummarizingApp/noiseRemove.py
LectureSummarizingApp/noiseRemove.py
+57
-0
No files found.
LectureSummarizingApp/noise.py
View file @
dc8d49fd
import
librosa
from
pysndfx
import
AudioEffectsChain
import
numpy
as
np
import
math
import
python_speech_features
import
scipy
as
sp
from
scipy
import
signal
import
soundfile
def
read_file
(
file_name
):
...
...
@@ -14,31 +10,18 @@ def read_file(file_name):
sample_path
=
sample_directory
+
sample_file
# generating audio time series and a sampling rate (int)
y
,
sr
=
librosa
.
load
(
sample_path
)
return
y
,
sr
a
,
sr
=
librosa
.
load
(
sample_path
)
# '''CENTROID'''
#
# def reduce_noise_centroid_s(y, sr):
#
# cent = librosa.feature.spectral_centroid(y=y, sr=sr)
# threshold_h = np.max(cent)
# threshold_l = np.min(cent)
# less_noise = AudioEffectsChain().lowshelf(gain=-12.0, frequency=threshold_l, slope=0.5).highshelf(gain=-12.0, frequency=threshold_h, slope=0.5).limiter(gain=6.0)
# y_cleaned = less_noise(y)
# return y_cleaned
#jijoijij
return
a
,
sr
'''MFCC'''
def
mffc_highshelf
(
y
,
sr
):
def
mffc_highshelf
(
a
,
sr
):
mfcc
=
python_speech_features
.
base
.
mfcc
(
y
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
y
)
mfcc
=
python_speech_features
.
base
.
mfcc
(
a
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
a
)
mfcc
=
python_speech_features
.
base
.
lifter
(
mfcc
)
sum_of_squares
=
[]
...
...
@@ -56,22 +39,22 @@ def mffc_highshelf(y, sr):
min_hz
=
min
(
hz
)
speech_booster
=
AudioEffectsChain
()
.
highshelf
(
frequency
=
min_hz
*
(
-
1
)
*
1.2
,
gain
=-
12.0
,
slope
=
0.6
)
.
limiter
(
gain
=
8.0
)
y_speach_boosted
=
speech_booster
(
y
)
a_speach_boosted
=
speech_booster
(
a
)
return
(
y
_speach_boosted
)
return
(
a
_speach_boosted
)
def
mfcc_lowshelf
(
y
,
sr
):
def
mfcc_lowshelf
(
a
,
sr
):
mfcc
=
python_speech_features
.
base
.
mfcc
(
y
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
y
)
mfcc
=
python_speech_features
.
base
.
mfcc
(
a
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
a
)
mfcc
=
python_speech_features
.
base
.
lifter
(
mfcc
)
sum_of_squares
=
[]
index
=
-
1
for
r
in
mfcc
:
for
x
in
mfcc
:
sum_of_squares
.
append
(
0
)
index
=
index
+
1
for
n
in
r
:
for
n
in
x
:
sum_of_squares
[
index
]
=
sum_of_squares
[
index
]
+
n
**
2
strongest_frame
=
sum_of_squares
.
index
(
max
(
sum_of_squares
))
...
...
@@ -81,49 +64,49 @@ def mfcc_lowshelf(y, sr):
min_hz
=
min
(
hz
)
speech_booster
=
AudioEffectsChain
()
.
lowshelf
(
frequency
=
min_hz
*
(
-
1
),
gain
=
12.0
,
slope
=
0.5
)
y_speach_boosted
=
speech_booster
(
y
)
a_speach_boosted
=
speech_booster
(
a
)
return
(
y
_speach_boosted
)
return
(
a
_speach_boosted
)
def
trim_silence
(
y
):
y
_trimmed
,
index
=
librosa
.
effects
.
trim
(
y
,
top_db
=
20
,
frame_length
=
2
,
hop_length
=
500
)
trimmed_length
=
librosa
.
get_duration
(
y
)
-
librosa
.
get_duration
(
y
_trimmed
)
a
_trimmed
,
index
=
librosa
.
effects
.
trim
(
y
,
top_db
=
20
,
frame_length
=
2
,
hop_length
=
500
)
trimmed_length
=
librosa
.
get_duration
(
y
)
-
librosa
.
get_duration
(
a
_trimmed
)
return
y
_trimmed
,
trimmed_length
return
a
_trimmed
,
trimmed_length
def
enhance
(
y
):
apply_audio_effects
=
AudioEffectsChain
()
.
lowshelf
(
gain
=
10.0
,
frequency
=
260
,
slope
=
0.1
)
.
reverb
(
reverberance
=
25
,
hf_damping
=
5
,
room_scale
=
5
,
stereo_depth
=
50
,
pre_delay
=
20
,
wet_gain
=
0
,
wet_only
=
False
)
#.normalize()
y
_enhanced
=
apply_audio_effects
(
y
)
a
_enhanced
=
apply_audio_effects
(
y
)
return
y
_enhanced
return
a
_enhanced
def
output_file
(
destination
,
filename
,
y
,
sr
,
ext
=
""
):
def
output_file
(
destination
,
filename
,
a
,
sr
,
ext
=
""
):
destination
=
destination
+
filename
[:
-
4
]
+
ext
+
'.wav'
librosa
.
output
.
write_wav
(
destination
,
y
,
sr
)
librosa
.
output
.
write_wav
(
destination
,
a
,
sr
)
lectures
=
[
'Lecture01.wav'
]
for
s
in
lectures
:
filename
=
s
y
,
sr
=
read_file
(
filename
)
a
,
sr
=
read_file
(
filename
)
#
y_reduced_centroid_s = reduce_noise_centroid_s(y
, sr)
y_reduced_mfcc_lowshelf
=
mfcc_lowshelf
(
y
,
sr
)
y_reduced_mfcc_highshelf
=
mffc_highshelf
(
y
,
sr
)
#
a_reduced_centroid_s = reduce_noise_centroid_s(a
, sr)
a_reduced_mfcc_lowshelf
=
mfcc_lowshelf
(
a
,
sr
)
a_reduced_mfcc_highshelf
=
mffc_highshelf
(
a
,
sr
)
# trimming silences
#
y_reduced_centroid_s, time_trimmed = trim_silence(y
_reduced_centroid_s)
y
_reduced_mfcc_up
,
time_trimmed
=
trim_silence
(
mfcc_lowshelf
)
y
_reduced_mfcc_down
,
time_trimmed
=
trim_silence
(
mffc_highshelf
)
#
a_reduced_centroid_s, time_trimmed = trim_silence(a
_reduced_centroid_s)
a
_reduced_mfcc_up
,
time_trimmed
=
trim_silence
(
mfcc_lowshelf
)
a
_reduced_mfcc_down
,
time_trimmed
=
trim_silence
(
mffc_highshelf
)
# output_file('lectures_trimmed_noise_reduced/' ,filename, y_reduced_centroid_s, sr, '_ctr_s')
output_file
(
'lectures_trimmed_noise_reduced/'
,
filename
,
y
_reduced_mfcc_up
,
sr
,
'_mfcc_up'
)
# output_file('lectures_trimmed_noise_reduced/' ,filename,
y
_reduced_mfcc_down, sr, '_mfcc_down')
# output_file('lectures_trimmed_noise_reduced/' ,filename,
y
, sr, '_org')
output_file
(
'lectures_trimmed_noise_reduced/'
,
filename
,
a
_reduced_mfcc_up
,
sr
,
'_mfcc_up'
)
# output_file('lectures_trimmed_noise_reduced/' ,filename,
a
_reduced_mfcc_down, sr, '_mfcc_down')
# output_file('lectures_trimmed_noise_reduced/' ,filename,
a
, sr, '_org')
LectureSummarizingApp/noiseRemove.py
0 → 100644
View file @
dc8d49fd
import
numpy
as
nump
import
scipy
as
sip
from
scipy.io.wavfile
import
read
from
scipy.io.wavfile
import
write
from
scipy
import
signal
import
matplotlib.pyplot
as
mplt
#get_ipython().magic('matplotlib inline')
(
Frequency
,
array
)
=
read
(
'lectures/Lecture01.wav'
)
len
(
array
)
mplt
.
plot
(
array
)
mplt
.
title
(
'Original Signal Spectrum'
)
mplt
.
xlabel
(
'Frequency(Hz)'
)
mplt
.
ylabel
(
'Amplitude'
)
fourierTransformation
=
sip
.
fft
(
array
)
scale
=
sip
.
linspace
(
0
,
Frequency
,
len
(
array
))
mplt
.
stem
(
scale
[
0
:
5000
],
nump
.
abs
(
fourierTransformation
[
0
:
5000
]),
'r'
)
mplt
.
title
(
'Signal spectrum after FFT'
)
mplt
.
xlabel
(
'Frequency(Hz)'
)
mplt
.
ylabel
(
'Amplitude'
)
guassianNoise
=
nump
.
random
.
rand
(
len
(
fourierTransformation
))
NewSound
=
guassianNoise
+
array
write
(
"New-Sound-Added-With-Guassian-Noise.wav"
,
Frequency
,
NewSound
)
u
,
v
=
signal
.
butter
(
5
,
1000
/
(
Frequency
/
2
),
btype
=
'highpass'
)
filteredSignal
=
signal
.
lfilter
(
u
,
v
,
NewSound
)
# plotting the signal.
mplt
.
plot
(
filteredSignal
)
mplt
.
title
(
'Highpass Filter'
)
mplt
.
xlabel
(
'Frequency(Hz)'
)
mplt
.
ylabel
(
'Amplitude'
)
# ButterWorth low-filter
x
,
y
=
signal
.
butter
(
5
,
380
/
(
Frequency
/
2
),
btype
=
'lowpass'
)
# Applying the filter to the signal
newFilteredSignal
=
signal
.
lfilter
(
x
,
y
,
filteredSignal
)
# plotting the signal.
mplt
.
plot
(
newFilteredSignal
)
mplt
.
title
(
'Lowpass Filter'
)
mplt
.
xlabel
(
'Frequency(Hz)'
)
mplt
.
ylabel
(
'Amplitude'
)
write
(
"removed.wav"
,
Frequency
,
nump
.
int16
(
newFilteredSignal
/
nump
.
max
(
nump
.
abs
(
newFilteredSignal
))
*
32767
))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment