"...text-generation-inference.git" did not exist on "a60fa8406abd98d41e2bfafaf6f81f3dd6044b15"
Unverified Commit 490a53e5 authored by Prabhat Roy's avatar Prabhat Roy Committed by GitHub
Browse files

Add GSM format support to sox_io's save function (#1275)

parent fa71c5e2
......@@ -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", ),
......
......@@ -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
......
......@@ -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());
......
......@@ -15,6 +15,7 @@ enum class Format {
AMR_WB,
AMB,
SPHERE,
GSM,
};
Format get_format_from_string(const std::string& format);
......
......@@ -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);
}
......
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