Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
21_22-J-02
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
21_22-J-02
21_22-J-02
Commits
7ebe4680
Commit
7ebe4680
authored
Jan 07, 2022
by
Shehara AKGH - IT18205152
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Audio Comparison - Signal Framing Completed
parent
15fe6897
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
87 deletions
+49
-87
BE-Pronunciation/Audio Comparison.py
BE-Pronunciation/Audio Comparison.py
+49
-87
No files found.
BE-Pronunciation/Audio Comparison.py
View file @
7ebe4680
...
...
@@ -51,99 +51,61 @@ np.allclose(y_filt, np.concatenate([y_filt_1, y_filt_2]))
# Framing and windowing of voice signals
# In[
21
]:
# In[
6
]:
def
framing
(
sig
,
fs
=
16000
,
win_len
=
0.025
,
win_hop
=
0.01
):
"""
transform a signal into a series of overlapping frames.
Args:
sig (array) : a mono audio signal (Nx1) from which to compute features.
fs (int) : the sampling frequency of the signal we are working with.
Default is 16000.
win_len (float) : window length in sec.
Default is 0.025.
win_hop (float) : step between successive windows in sec.
Default is 0.01.
Returns:
array of frames.
frame length.
"""
#
# # pre-emphasis
# if pre_emph:
# sig = pre_emphasis(sig=sig, pre_emph_coeff=0.97)
#
# # -> framing
# frames, frame_length = framing(sig=sig,
# fs=fs,
# win_len=win_len,
# win_hop=win_hop)
#
# # -> windowing
# windows = windowing(frames=frames,
# frame_len=frame_length,
# win_type=win_type)
#
# In[25]:
# compute frame length and frame step (convert from seconds to samples)
import
numpy
as
np
frame_length
=
win_len
*
fs
frame_step
=
win_hop
*
fs
signal_length
=
len
(
sig
)
frames_overlap
=
frame_length
-
frame_step
def
framing
(
sig
,
fs
=
16000
,
win_len
=
0.025
,
win_hop
=
0.01
):
"""
transform a signal into a series of overlapping frames.
Args:
sig (array) : a mono audio signal (Nx1) from which to compute features.
fs (int) : the sampling frequency of the signal we are working with.
Default is 16000.
win_len (float) : window length in sec.
Default is 0.025.
win_hop (float) : step between successive windows in sec.
Default is 0.01.
Returns:
array of frames.
frame length.
"""
# compute frame length and frame step (convert from seconds to samples)
frame_length
=
win_len
*
fs
frame_step
=
win_hop
*
fs
signal_length
=
len
(
sig
)
frames_overlap
=
frame_length
-
frame_step
# Make sure that we have at least 1 frame+
num_frames
=
np
.
abs
(
signal_length
-
frames_overlap
)
//
np
.
abs
(
frame_length
-
frames_overlap
)
rest_samples
=
np
.
abs
(
signal_length
-
frames_overlap
)
%
np
.
abs
(
frame_length
-
frames_overlap
)
# Pad Signal to make sure that all frames have equal number of samples
# without truncating any samples from the original signal
if
rest_samples
!=
0
:
pad_signal_length
=
int
(
frame_step
-
rest_samples
)
z
=
np
.
zeros
((
pad_signal_length
))
pad_signal
=
np
.
append
(
sig
,
z
)
num_frames
+=
1
else
:
pad_signal
=
sig
# make sure to use integers as indices
frame_length
=
int
(
frame_length
)
frame_step
=
int
(
frame_step
)
num_frames
=
int
(
num_frames
)
# compute indices
idx1
=
np
.
tile
(
np
.
arange
(
0
,
frame_length
),
(
num_frames
,
1
))
idx2
=
np
.
tile
(
np
.
arange
(
0
,
num_frames
*
frame_step
,
frame_step
),
(
frame_length
,
1
))
.
T
indices
=
idx1
+
idx2
frames
=
pad_signal
[
indices
.
astype
(
np
.
int32
,
copy
=
False
)]
return
frames
# In[ ]:
# In[ ]:
num_frames
=
np
.
abs
(
signal_length
-
frames_overlap
)
//
np
.
abs
(
frame_length
-
frames_overlap
)
rest_samples
=
np
.
abs
(
signal_length
-
frames_overlap
)
%
np
.
abs
(
frame_length
-
frames_overlap
)
# Pad Signal to make sure that all frames have equal number of samples
# without truncating any samples from the original signal
if
rest_samples
!=
0
:
pad_signal_length
=
int
(
frame_step
-
rest_samples
)
z
=
np
.
zeros
((
pad_signal_length
))
pad_signal
=
np
.
append
(
sig
,
z
)
num_frames
+=
1
else
:
pad_signal
=
sig
# make sure to use integers as indices
frame_length
=
int
(
frame_length
)
frame_step
=
int
(
frame_step
)
num_frames
=
int
(
num_frames
)
# compute indices
idx1
=
np
.
tile
(
np
.
arange
(
0
,
frame_length
),
(
num_frames
,
1
))
idx2
=
np
.
tile
(
np
.
arange
(
0
,
num_frames
*
frame_step
,
frame_step
),
(
frame_length
,
1
))
.
T
indices
=
idx1
+
idx2
frames
=
pad_signal
[
indices
.
astype
(
np
.
int32
,
copy
=
False
)]
return
frames
# In[ ]:
...
...
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