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
53f420ec
Commit
53f420ec
authored
Nov 05, 2020
by
LiniEisha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformatting noise.py
parent
12d23d82
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
31 deletions
+31
-31
LectureSummarizingApp/noise.py
LectureSummarizingApp/noise.py
+31
-31
No files found.
LectureSummarizingApp/noise.py
View file @
53f420ec
...
@@ -10,18 +10,18 @@ def read_file(file_name):
...
@@ -10,18 +10,18 @@ def read_file(file_name):
sample_path
=
sample_directory
+
sample_file
sample_path
=
sample_directory
+
sample_file
# generating audio time series and a sampling rate (int)
# generating audio time series and a sampling rate (int)
y
,
sr
=
librosa
.
load
(
sample_path
)
a
,
sr
=
librosa
.
load
(
sample_path
)
return
y
,
sr
return
a
,
sr
'''MFCC'''
'''MFCC'''
def
mffc_highshelf
(
y
,
sr
):
def
mffc_highshelf
(
a
,
sr
):
mfcc
=
python_speech_features
.
base
.
mfcc
(
y
)
mfcc
=
python_speech_features
.
base
.
mfcc
(
a
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
y
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
a
)
mfcc
=
python_speech_features
.
base
.
lifter
(
mfcc
)
mfcc
=
python_speech_features
.
base
.
lifter
(
mfcc
)
sum_of_squares
=
[]
sum_of_squares
=
[]
...
@@ -39,22 +39,22 @@ def mffc_highshelf(y, sr):
...
@@ -39,22 +39,22 @@ def mffc_highshelf(y, sr):
min_hz
=
min
(
hz
)
min_hz
=
min
(
hz
)
speech_booster
=
AudioEffectsChain
()
.
highshelf
(
frequency
=
min_hz
*
(
-
1
)
*
1.2
,
gain
=-
12.0
,
slope
=
0.6
)
.
limiter
(
gain
=
8.0
)
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
.
mfcc
(
a
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
y
)
mfcc
=
python_speech_features
.
base
.
logfbank
(
a
)
mfcc
=
python_speech_features
.
base
.
lifter
(
mfcc
)
mfcc
=
python_speech_features
.
base
.
lifter
(
mfcc
)
sum_of_squares
=
[]
sum_of_squares
=
[]
index
=
-
1
index
=
-
1
for
r
in
mfcc
:
for
x
in
mfcc
:
sum_of_squares
.
append
(
0
)
sum_of_squares
.
append
(
0
)
index
=
index
+
1
index
=
index
+
1
for
n
in
r
:
for
n
in
x
:
sum_of_squares
[
index
]
=
sum_of_squares
[
index
]
+
n
**
2
sum_of_squares
[
index
]
=
sum_of_squares
[
index
]
+
n
**
2
strongest_frame
=
sum_of_squares
.
index
(
max
(
sum_of_squares
))
strongest_frame
=
sum_of_squares
.
index
(
max
(
sum_of_squares
))
...
@@ -64,49 +64,49 @@ def mfcc_lowshelf(y, sr):
...
@@ -64,49 +64,49 @@ def mfcc_lowshelf(y, sr):
min_hz
=
min
(
hz
)
min_hz
=
min
(
hz
)
speech_booster
=
AudioEffectsChain
()
.
lowshelf
(
frequency
=
min_hz
*
(
-
1
),
gain
=
12.0
,
slope
=
0.5
)
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
):
def
trim_silence
(
y
):
y
_trimmed
,
index
=
librosa
.
effects
.
trim
(
y
,
top_db
=
20
,
frame_length
=
2
,
hop_length
=
500
)
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
(
y
_trimmed
)
trimmed_length
=
librosa
.
get_duration
(
y
)
-
librosa
.
get_duration
(
a
_trimmed
)
return
y
_trimmed
,
trimmed_length
return
a
_trimmed
,
trimmed_length
def
enhance
(
y
):
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()
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'
destination
=
destination
+
filename
[:
-
4
]
+
ext
+
'.wav'
librosa
.
output
.
write_wav
(
destination
,
y
,
sr
)
librosa
.
output
.
write_wav
(
destination
,
a
,
sr
)
lectures
=
[
'Lecture01.wav'
]
lectures
=
[
'Lecture01.wav'
]
for
s
in
lectures
:
for
s
in
lectures
:
filename
=
s
filename
=
s
y
,
sr
=
read_file
(
filename
)
a
,
sr
=
read_file
(
filename
)
#
y_reduced_centroid_s = reduce_noise_centroid_s(y
, sr)
#
a_reduced_centroid_s = reduce_noise_centroid_s(a
, sr)
y_reduced_mfcc_lowshelf
=
mfcc_lowshelf
(
y
,
sr
)
a_reduced_mfcc_lowshelf
=
mfcc_lowshelf
(
a
,
sr
)
y_reduced_mfcc_highshelf
=
mffc_highshelf
(
y
,
sr
)
a_reduced_mfcc_highshelf
=
mffc_highshelf
(
a
,
sr
)
# trimming silences
# trimming silences
#
y_reduced_centroid_s, time_trimmed = trim_silence(y
_reduced_centroid_s)
#
a_reduced_centroid_s, time_trimmed = trim_silence(a
_reduced_centroid_s)
y
_reduced_mfcc_up
,
time_trimmed
=
trim_silence
(
mfcc_lowshelf
)
a
_reduced_mfcc_up
,
time_trimmed
=
trim_silence
(
mfcc_lowshelf
)
y
_reduced_mfcc_down
,
time_trimmed
=
trim_silence
(
mffc_highshelf
)
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_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
,
a
_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,
a
_reduced_mfcc_down, sr, '_mfcc_down')
# output_file('lectures_trimmed_noise_reduced/' ,filename,
y
, sr, '_org')
# output_file('lectures_trimmed_noise_reduced/' ,filename,
a
, sr, '_org')
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