"vscode:/vscode.git/clone" did not exist on "8acb270c90d0f400e9538db2e665dc61e8907a2f"
Unverified Commit f2b183ee authored by SJ's avatar SJ Committed by GitHub
Browse files

Add GSM encoding support to info (#1277)

parent d2861fc2
...@@ -221,6 +221,21 @@ class TestInfo(TempDirMixin, PytorchTestCase): ...@@ -221,6 +221,21 @@ class TestInfo(TempDirMixin, PytorchTestCase):
assert info.bits_per_sample == 8 assert info.bits_per_sample == 8
assert info.encoding == "ALAW" 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): def test_htk(self):
"""`sox_io_backend.info` can check HTK file correctly""" """`sox_io_backend.info` can check HTK file correctly"""
duration = 1 duration = 1
......
#include <sox.h>
#include <torchaudio/csrc/sox/effects.h> #include <torchaudio/csrc/sox/effects.h>
#include <torchaudio/csrc/sox/effects_chain.h> #include <torchaudio/csrc/sox/effects_chain.h>
#include <torchaudio/csrc/sox/io.h> #include <torchaudio/csrc/sox/io.h>
#include <torchaudio/csrc/sox/types.h>
#include <torchaudio/csrc/sox/utils.h> #include <torchaudio/csrc/sox/utils.h>
using namespace torch::indexing; using namespace torch::indexing;
...@@ -10,41 +10,6 @@ using namespace torchaudio::sox_utils; ...@@ -10,41 +10,6 @@ using namespace torchaudio::sox_utils;
namespace torchaudio { namespace torchaudio {
namespace sox_io { 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( std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path, const std::string& path,
c10::optional<std::string> format) { c10::optional<std::string> format) {
......
...@@ -102,5 +102,38 @@ BitDepth get_bit_depth_from_option(const c10::optional<int64_t> bit_depth) { ...@@ -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 sox_utils
} // namespace torchaudio } // namespace torchaudio
#ifndef TORCHAUDIO_SOX_TYPES_H #ifndef TORCHAUDIO_SOX_TYPES_H
#define TORCHAUDIO_SOX_TYPES_H #define TORCHAUDIO_SOX_TYPES_H
#include <sox.h>
#include <torch/script.h> #include <torch/script.h>
namespace torchaudio { namespace torchaudio {
...@@ -51,6 +52,8 @@ enum class BitDepth : unsigned { ...@@ -51,6 +52,8 @@ enum class BitDepth : unsigned {
BitDepth get_bit_depth_from_option(const c10::optional<int64_t> bit_depth); 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 sox_utils
} // namespace torchaudio } // namespace torchaudio
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment