Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
public_projects
ketos
Commits
2768c76c
Commit
2768c76c
authored
6 years ago
by
Oliver Kirsebom
Browse files
Options
Download
Email Patches
Plain Diff
audio_signal.py - ENH - crop method modifies instance instead of returning new instance
parent
74fee9de
1 merge request
!42
audio_signal.py - ENH - crop method modifies instance instead of returning new instance
Pipeline
#373
passed with stage
in 4 minutes and 26 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sound_classification/audio_signal.py
+6
-10
sound_classification/audio_signal.py
sound_classification/tests/test_audio_signal.py
+3
-2
sound_classification/tests/test_audio_signal.py
with
9 additions
and
12 deletions
+9
-12
sound_classification/audio_signal.py
View file @
2768c76c
...
...
@@ -53,9 +53,7 @@ class AudioSignal:
return
np
.
array
(
cropped_data
)
def
crop
(
self
,
begin
=
None
,
end
=
None
):
cropped_data
=
self
.
_cropped_data
(
begin
,
end
)
cropped_signal
=
self
.
__class__
(
rate
=
self
.
rate
,
data
=
cropped_data
)
return
cropped_signal
self
.
data
=
self
.
_cropped_data
(
begin
,
end
)
def
append
(
self
,
signal
,
overlap_sec
=
0
):
assert
self
.
rate
==
signal
.
rate
,
"Cannot merge audio signals with different sampling rates."
...
...
@@ -137,15 +135,13 @@ class TimeStampedAudioSignal(AudioSignal):
def
crop
(
self
,
begin
=
None
,
end
=
None
):
begin_sec
,
end_sec
=
None
,
None
if
begin
is
not
None
:
begin_sec
=
(
begin
-
self
.
begin
()).
total_seconds
()
if
end
is
not
None
:
end_sec
=
(
end
-
self
.
begin
()).
total_seconds
()
cropped_data
=
self
.
_cropped_data
(
begin_sec
,
end_sec
)
self
.
data
=
self
.
_cropped_data
(
begin_sec
,
end_sec
)
time_stamp
=
self
.
time_stamp
if
begin_sec
>
0
and
len
(
cropped_data
)
>
0
:
time_stamp
+=
datetime
.
timedelta
(
seconds
=
begin_sec
)
# update time stamp
cropped_signal
=
self
.
__class__
(
rate
=
self
.
rate
,
data
=
cropped_data
,
time_stamp
=
time_stamp
,
tag
=
self
.
tag
)
return
cropped_signal
\ No newline at end of file
if
begin_sec
>
0
and
len
(
self
.
data
)
>
0
:
self
.
time_stamp
+=
datetime
.
timedelta
(
seconds
=
begin_sec
)
# update time stamp
This diff is collapsed.
Click to expand it.
sound_classification/tests/test_audio_signal.py
View file @
2768c76c
...
...
@@ -43,7 +43,8 @@ def test_crop_audio_signal(audio):
seconds
=
len
(
audio
.
data
)
/
audio
.
rate
crop_begin
=
audio
.
begin
()
+
datetime
.
timedelta
(
seconds
=
seconds
/
10.
)
crop_end
=
audio
.
end
()
-
datetime
.
timedelta
(
seconds
=
seconds
/
10.
)
audio_cropped
=
audio
.
crop
(
begin
=
crop_begin
,
end
=
crop_end
)
audio_cropped
=
audio
audio_cropped
.
crop
(
begin
=
crop_begin
,
end
=
crop_end
)
seconds_cropped
=
len
(
audio_cropped
.
data
)
/
audio_cropped
.
rate
assert
seconds_cropped
/
seconds
==
pytest
.
approx
(
8.
/
10.
,
rel
=
1.
/
audio
.
rate
)
assert
audio_cropped
.
begin
()
==
crop_begin
...
...
@@ -61,4 +62,4 @@ def test_append_audio_signal_without_time_stamp(audio, audio_without_time_stamp)
def
test_append_audio_signal_with_smoothing
(
audio
):
t
=
audio
.
seconds
()
audio
.
append
(
signal
=
audio
,
overlap_sec
=
0.2
)
assert
audio
.
seconds
()
==
pytest
.
approx
(
2.
*
t
-
0.2
,
rel
=
1.
/
audio
.
rate
)
\ No newline at end of file
assert
audio
.
seconds
()
==
pytest
.
approx
(
2.
*
t
-
0.2
,
rel
=
1.
/
audio
.
rate
)
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help