Skip to content

Commit a751e1d

Browse files
authored
Hot fix for GSM load support (#1313)
Some audio formats like `gsm` does not have valid frame numbers when opened. But `libsox` can properly handle these audios, so checking if `length > 0` is not necessary and too strict. (cherry picked from commit 086467a)
1 parent 5784b81 commit a751e1d

File tree

4 files changed

+4
-7
lines changed

4 files changed

+4
-7
lines changed

torchaudio/csrc/sox/effects.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ std::tuple<torch::Tensor, int64_t> apply_effects_fileobj(
204204
/*filetype=*/format.has_value() ? format.value().c_str() : nullptr));
205205

206206
// In case of streamed data, length can be 0
207-
validate_input_file(sf, /*check_length=*/false);
207+
validate_input_file(sf);
208208

209209
// Prepare output buffer
210210
std::vector<sox_sample_t> out_buffer;

torchaudio/csrc/sox/io.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_fileobj(
170170
/*filetype=*/format.has_value() ? format.value().c_str() : nullptr));
171171

172172
// In case of streamed data, length can be 0
173-
validate_input_file(sf, /*check_length=*/false);
173+
validate_input_file(sf);
174174

175175
return std::make_tuple(
176176
static_cast<int64_t>(sf->signal.rate),

torchaudio/csrc/sox/utils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,13 @@ void SoxFormat::close() {
8181
}
8282
}
8383

84-
void validate_input_file(const SoxFormat& sf, bool check_length) {
84+
void validate_input_file(const SoxFormat& sf) {
8585
if (static_cast<sox_format_t*>(sf) == nullptr) {
8686
throw std::runtime_error("Error loading audio file: failed to open file.");
8787
}
8888
if (sf->encoding.encoding == SOX_ENCODING_UNKNOWN) {
8989
throw std::runtime_error("Error loading audio file: unknown encoding.");
9090
}
91-
if (check_length && sf->signal.length == 0) {
92-
throw std::runtime_error("Error reading audio file: unknown length.");
93-
}
9491
}
9592

9693
void validate_input_tensor(const torch::Tensor tensor) {

torchaudio/csrc/sox/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct SoxFormat {
5656

5757
///
5858
/// Verify that input file is found, has known encoding, and not empty
59-
void validate_input_file(const SoxFormat& sf, bool check_length = true);
59+
void validate_input_file(const SoxFormat& sf);
6060

6161
///
6262
/// Verify that input Tensor is 2D, CPU and either uin8, int16, int32 or float32

0 commit comments

Comments
 (0)