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
"...text-generation-inference.git" did not exist on "a60fa8406abd98d41e2bfafaf6f81f3dd6044b15"
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
Hide 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):
self
.
assert_save_consistency
(
"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
([
(
"wav"
,
"PCM_S"
,
16
),
(
"mp3"
,
),
...
...
torchaudio/backend/sox_io_backend.py
View file @
490a53e5
...
...
@@ -195,7 +195,7 @@ def save(
When ``filepath`` argument is file-like object, this argument is required.
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.
This argument is effective only for supported formats, cush as ``"wav"``, ``""amb"``
and ``"sph"``. Valid values are;
...
...
@@ -291,6 +291,9 @@ def save(
``"amr-nb"``
Bitrate ranging from 4.75 kbit/s to 12.2 kbit/s. Default: 4.75 kbit/s
``"gsm"``
Lossy Speech Compression, CPU intensive.
Note:
To save into formats that ``libsox`` does not handle natively, (such as ``"mp3"``,
``"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) {
return
Format
::
AMB
;
if
(
format
==
"sph"
)
return
Format
::
SPHERE
;
if
(
format
==
"gsm"
)
return
Format
::
GSM
;
std
::
ostringstream
stream
;
stream
<<
"Internal Error: unexpected format value: "
<<
format
;
throw
std
::
runtime_error
(
stream
.
str
());
...
...
torchaudio/csrc/sox/types.h
View file @
490a53e5
...
...
@@ -15,6 +15,7 @@ enum class Format {
AMR_WB
,
AMB
,
SPHERE
,
GSM
,
};
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(
throw
std
::
runtime_error
(
"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:
throw
std
::
runtime_error
(
"Unsupported format: "
+
format
);
}
...
...
@@ -409,6 +417,8 @@ unsigned get_precision(const std::string filetype, caffe2::TypeMeta dtype) {
if
(
filetype
==
"amr-nb"
)
{
return
16
;
}
if
(
filetype
==
"gsm"
)
return
16
;
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