Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
47d00080
"vscode:/vscode.git/clone" did not exist on "d533e9ba62ebc5ed45ab2723c8a2c9f5598a9727"
Unverified
Commit
47d00080
authored
Mar 11, 2021
by
Jason Hurt
Committed by
GitHub
Mar 11, 2021
Browse files
Reject saving GSM when not compatible (#1384)
parent
6d81ab8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
test/torchaudio_unittest/backend/sox_io/save_test.py
test/torchaudio_unittest/backend/sox_io/save_test.py
+9
-1
torchaudio/csrc/sox/io.cpp
torchaudio/csrc/sox/io.cpp
+17
-0
No files found.
test/torchaudio_unittest/backend/sox_io/save_test.py
View file @
47d00080
...
...
@@ -305,7 +305,15 @@ class SaveTest(SaveTestBase):
)
def
test_save_gsm
(
self
,
test_mode
):
self
.
assert_save_consistency
(
"gsm"
,
test_mode
=
test_mode
)
"gsm"
,
num_channels
=
1
,
test_mode
=
test_mode
)
with
self
.
assertRaises
(
RuntimeError
,
msg
=
"gsm format only supports single channel audio."
):
self
.
assert_save_consistency
(
"gsm"
,
num_channels
=
2
,
test_mode
=
test_mode
)
with
self
.
assertRaises
(
RuntimeError
,
msg
=
"gsm format only supports a sampling rate of 8kHz."
):
self
.
assert_save_consistency
(
"gsm"
,
sample_rate
=
16000
,
test_mode
=
test_mode
)
@
parameterized
.
expand
([
(
"wav"
,
"PCM_S"
,
16
),
...
...
torchaudio/csrc/sox/io.cpp
View file @
47d00080
...
...
@@ -101,6 +101,13 @@ void save_audio_file(
const
auto
num_channels
=
tensor
.
size
(
channels_first
?
0
:
1
);
TORCH_CHECK
(
num_channels
==
1
,
"htk format only supports single channel audio."
);
}
else
if
(
filetype
==
"gsm"
)
{
const
auto
num_channels
=
tensor
.
size
(
channels_first
?
0
:
1
);
TORCH_CHECK
(
num_channels
==
1
,
"gsm format only supports single channel audio."
);
TORCH_CHECK
(
sample_rate
==
8000
,
"gsm format only supports a sampling rate of 8kHz."
);
}
const
auto
signal_info
=
get_signalinfo
(
&
tensor
,
sample_rate
,
filetype
,
channels_first
);
...
...
@@ -243,6 +250,16 @@ void save_audio_fileobj(
throw
std
::
runtime_error
(
"htk format only supports single channel audio."
);
}
}
else
if
(
filetype
==
"gsm"
)
{
const
auto
num_channels
=
tensor
.
size
(
channels_first
?
0
:
1
);
if
(
num_channels
!=
1
)
{
throw
std
::
runtime_error
(
"gsm format only supports single channel audio."
);
}
if
(
sample_rate
!=
8000
)
{
throw
std
::
runtime_error
(
"gsm format only supports a sampling rate of 8kHz."
);
}
}
const
auto
signal_info
=
get_signalinfo
(
&
tensor
,
sample_rate
,
filetype
,
channels_first
);
...
...
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