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
490a53e5
"vscode:/vscode.git/clone" did not exist on "b25f81e0ea098f84fb8f8c4f238937b18db1d953"
Unverified
Commit
490a53e5
authored
Feb 18, 2021
by
Prabhat Roy
Committed by
GitHub
Feb 17, 2021
Browse files
Add GSM format support to sox_io's save function (#1275)
parent
fa71c5e2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
1 deletion
+24
-1
test/torchaudio_unittest/backend/sox_io/save_test.py
test/torchaudio_unittest/backend/sox_io/save_test.py
+7
-0
torchaudio/backend/sox_io_backend.py
torchaudio/backend/sox_io_backend.py
+4
-1
torchaudio/csrc/sox/types.cpp
torchaudio/csrc/sox/types.cpp
+2
-0
torchaudio/csrc/sox/types.h
torchaudio/csrc/sox/types.h
+1
-0
torchaudio/csrc/sox/utils.cpp
torchaudio/csrc/sox/utils.cpp
+10
-0
No files found.
test/torchaudio_unittest/backend/sox_io/save_test.py
View file @
490a53e5
...
@@ -310,6 +310,13 @@ class SaveTest(SaveTestBase):
...
@@ -310,6 +310,13 @@ class SaveTest(SaveTestBase):
self
.
assert_save_consistency
(
self
.
assert_save_consistency
(
"amr-nb"
,
compression
=
bit_rate
,
num_channels
=
1
,
test_mode
=
test_mode
)
"amr-nb"
,
compression
=
bit_rate
,
num_channels
=
1
,
test_mode
=
test_mode
)
@
nested_params
(
[
"path"
,
"fileobj"
,
"bytesio"
],
)
def
test_save_gsm
(
self
,
test_mode
):
self
.
assert_save_consistency
(
"gsm"
,
test_mode
=
test_mode
)
@
parameterized
.
expand
([
@
parameterized
.
expand
([
(
"wav"
,
"PCM_S"
,
16
),
(
"wav"
,
"PCM_S"
,
16
),
(
"mp3"
,
),
(
"mp3"
,
),
...
...
torchaudio/backend/sox_io_backend.py
View file @
490a53e5
...
@@ -195,7 +195,7 @@ def save(
...
@@ -195,7 +195,7 @@ def save(
When ``filepath`` argument is file-like object, this argument is required.
When ``filepath`` argument is file-like object, this argument is required.
Valid values are ``"wav"``, ``"mp3"``, ``"ogg"``, ``"vorbis"``, ``"amr-nb"``,
Valid values are ``"wav"``, ``"mp3"``, ``"ogg"``, ``"vorbis"``, ``"amr-nb"``,
``"amb"``, ``"flac"`` and ``"
sph
"``.
``"amb"``, ``"flac"``
, ``"sph"``
and ``"
gsm
"``.
encoding (str, optional): Changes the encoding for the supported formats.
encoding (str, optional): Changes the encoding for the supported formats.
This argument is effective only for supported formats, cush as ``"wav"``, ``""amb"``
This argument is effective only for supported formats, cush as ``"wav"``, ``""amb"``
and ``"sph"``. Valid values are;
and ``"sph"``. Valid values are;
...
@@ -291,6 +291,9 @@ def save(
...
@@ -291,6 +291,9 @@ def save(
``"amr-nb"``
``"amr-nb"``
Bitrate ranging from 4.75 kbit/s to 12.2 kbit/s. Default: 4.75 kbit/s
Bitrate ranging from 4.75 kbit/s to 12.2 kbit/s. Default: 4.75 kbit/s
``"gsm"``
Lossy Speech Compression, CPU intensive.
Note:
Note:
To save into formats that ``libsox`` does not handle natively, (such as ``"mp3"``,
To save into formats that ``libsox`` does not handle natively, (such as ``"mp3"``,
``"flac"``, ``"ogg"`` and ``"vorbis"``), your installation of ``torchaudio`` has
``"flac"``, ``"ogg"`` and ``"vorbis"``), your installation of ``torchaudio`` has
...
...
torchaudio/csrc/sox/types.cpp
View file @
490a53e5
...
@@ -20,6 +20,8 @@ Format get_format_from_string(const std::string& format) {
...
@@ -20,6 +20,8 @@ Format get_format_from_string(const std::string& format) {
return
Format
::
AMB
;
return
Format
::
AMB
;
if
(
format
==
"sph"
)
if
(
format
==
"sph"
)
return
Format
::
SPHERE
;
return
Format
::
SPHERE
;
if
(
format
==
"gsm"
)
return
Format
::
GSM
;
std
::
ostringstream
stream
;
std
::
ostringstream
stream
;
stream
<<
"Internal Error: unexpected format value: "
<<
format
;
stream
<<
"Internal Error: unexpected format value: "
<<
format
;
throw
std
::
runtime_error
(
stream
.
str
());
throw
std
::
runtime_error
(
stream
.
str
());
...
...
torchaudio/csrc/sox/types.h
View file @
490a53e5
...
@@ -15,6 +15,7 @@ enum class Format {
...
@@ -15,6 +15,7 @@ enum class Format {
AMR_WB
,
AMR_WB
,
AMB
,
AMB
,
SPHERE
,
SPHERE
,
GSM
,
};
};
Format
get_format_from_string
(
const
std
::
string
&
format
);
Format
get_format_from_string
(
const
std
::
string
&
format
);
...
...
torchaudio/csrc/sox/utils.cpp
View file @
490a53e5
...
@@ -378,6 +378,14 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding(
...
@@ -378,6 +378,14 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding(
throw
std
::
runtime_error
(
throw
std
::
runtime_error
(
"sph does not support encoding: "
+
encoding
.
value
());
"sph does not support encoding: "
+
encoding
.
value
());
}
}
case
Format
::
GSM
:
if
(
enc
!=
Encoding
::
NOT_PROVIDED
)
throw
std
::
runtime_error
(
"gsm does not support `encoding` option."
);
if
(
bps
!=
BitDepth
::
NOT_PROVIDED
)
throw
std
::
runtime_error
(
"gsm does not support `bits_per_sample` option."
);
return
std
::
make_tuple
<>
(
SOX_ENCODING_GSM
,
16
);
default:
default:
throw
std
::
runtime_error
(
"Unsupported format: "
+
format
);
throw
std
::
runtime_error
(
"Unsupported format: "
+
format
);
}
}
...
@@ -409,6 +417,8 @@ unsigned get_precision(const std::string filetype, caffe2::TypeMeta dtype) {
...
@@ -409,6 +417,8 @@ unsigned get_precision(const std::string filetype, caffe2::TypeMeta dtype) {
if
(
filetype
==
"amr-nb"
)
{
if
(
filetype
==
"amr-nb"
)
{
return
16
;
return
16
;
}
}
if
(
filetype
==
"gsm"
)
return
16
;
throw
std
::
runtime_error
(
"Unsupported file type: "
+
filetype
);
throw
std
::
runtime_error
(
"Unsupported file type: "
+
filetype
);
}
}
...
...
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