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
f2b183ee
Unverified
Commit
f2b183ee
authored
Feb 19, 2021
by
SJ
Committed by
GitHub
Feb 19, 2021
Browse files
Add GSM encoding support to info (#1277)
parent
d2861fc2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
36 deletions
+52
-36
test/torchaudio_unittest/backend/sox_io/info_test.py
test/torchaudio_unittest/backend/sox_io/info_test.py
+15
-0
torchaudio/csrc/sox/io.cpp
torchaudio/csrc/sox/io.cpp
+1
-36
torchaudio/csrc/sox/types.cpp
torchaudio/csrc/sox/types.cpp
+33
-0
torchaudio/csrc/sox/types.h
torchaudio/csrc/sox/types.h
+3
-0
No files found.
test/torchaudio_unittest/backend/sox_io/info_test.py
View file @
f2b183ee
...
...
@@ -221,6 +221,21 @@ class TestInfo(TempDirMixin, PytorchTestCase):
assert
info
.
bits_per_sample
==
8
assert
info
.
encoding
==
"ALAW"
def
test_gsm
(
self
):
"""`sox_io_backend.info` can check gsm file correctly"""
duration
=
1
num_channels
=
1
sample_rate
=
8000
path
=
self
.
get_temp_path
(
'data.gsm'
)
sox_utils
.
gen_audio_file
(
path
,
sample_rate
=
sample_rate
,
num_channels
=
num_channels
,
duration
=
duration
)
info
=
sox_io_backend
.
info
(
path
)
assert
info
.
sample_rate
==
sample_rate
assert
info
.
num_channels
==
num_channels
assert
info
.
bits_per_sample
==
0
assert
info
.
encoding
==
"GSM"
def
test_htk
(
self
):
"""`sox_io_backend.info` can check HTK file correctly"""
duration
=
1
...
...
torchaudio/csrc/sox/io.cpp
View file @
f2b183ee
#include <sox.h>
#include <torchaudio/csrc/sox/effects.h>
#include <torchaudio/csrc/sox/effects_chain.h>
#include <torchaudio/csrc/sox/io.h>
#include <torchaudio/csrc/sox/types.h>
#include <torchaudio/csrc/sox/utils.h>
using
namespace
torch
::
indexing
;
...
...
@@ -10,41 +10,6 @@ using namespace torchaudio::sox_utils;
namespace
torchaudio
{
namespace
sox_io
{
namespace
{
std
::
string
get_encoding
(
sox_encoding_t
encoding
)
{
switch
(
encoding
)
{
case
SOX_ENCODING_UNKNOWN
:
return
"UNKNOWN"
;
case
SOX_ENCODING_SIGN2
:
return
"PCM_S"
;
case
SOX_ENCODING_UNSIGNED
:
return
"PCM_U"
;
case
SOX_ENCODING_FLOAT
:
return
"PCM_F"
;
case
SOX_ENCODING_FLAC
:
return
"FLAC"
;
case
SOX_ENCODING_ULAW
:
return
"ULAW"
;
case
SOX_ENCODING_ALAW
:
return
"ALAW"
;
case
SOX_ENCODING_MP3
:
return
"MP3"
;
case
SOX_ENCODING_VORBIS
:
return
"VORBIS"
;
case
SOX_ENCODING_AMR_WB
:
return
"AMR_WB"
;
case
SOX_ENCODING_AMR_NB
:
return
"AMR_NB"
;
case
SOX_ENCODING_OPUS
:
return
"OPUS"
;
default:
return
"UNKNOWN"
;
}
}
}
// namespace
std
::
tuple
<
int64_t
,
int64_t
,
int64_t
,
int64_t
,
std
::
string
>
get_info_file
(
const
std
::
string
&
path
,
c10
::
optional
<
std
::
string
>
format
)
{
...
...
torchaudio/csrc/sox/types.cpp
View file @
f2b183ee
...
...
@@ -102,5 +102,38 @@ BitDepth get_bit_depth_from_option(const c10::optional<int64_t> bit_depth) {
}
}
std
::
string
get_encoding
(
sox_encoding_t
encoding
)
{
switch
(
encoding
)
{
case
SOX_ENCODING_UNKNOWN
:
return
"UNKNOWN"
;
case
SOX_ENCODING_SIGN2
:
return
"PCM_S"
;
case
SOX_ENCODING_UNSIGNED
:
return
"PCM_U"
;
case
SOX_ENCODING_FLOAT
:
return
"PCM_F"
;
case
SOX_ENCODING_FLAC
:
return
"FLAC"
;
case
SOX_ENCODING_ULAW
:
return
"ULAW"
;
case
SOX_ENCODING_ALAW
:
return
"ALAW"
;
case
SOX_ENCODING_MP3
:
return
"MP3"
;
case
SOX_ENCODING_VORBIS
:
return
"VORBIS"
;
case
SOX_ENCODING_AMR_WB
:
return
"AMR_WB"
;
case
SOX_ENCODING_AMR_NB
:
return
"AMR_NB"
;
case
SOX_ENCODING_OPUS
:
return
"OPUS"
;
case
SOX_ENCODING_GSM
:
return
"GSM"
;
default:
return
"UNKNOWN"
;
}
}
}
// namespace sox_utils
}
// namespace torchaudio
torchaudio/csrc/sox/types.h
View file @
f2b183ee
#ifndef TORCHAUDIO_SOX_TYPES_H
#define TORCHAUDIO_SOX_TYPES_H
#include <sox.h>
#include <torch/script.h>
namespace
torchaudio
{
...
...
@@ -51,6 +52,8 @@ enum class BitDepth : unsigned {
BitDepth
get_bit_depth_from_option
(
const
c10
::
optional
<
int64_t
>
bit_depth
);
std
::
string
get_encoding
(
sox_encoding_t
encoding
);
}
// namespace sox_utils
}
// namespace torchaudio
...
...
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