Skip to content

Commit

Permalink
Work around missing locale when running with musl libc.
Browse files Browse the repository at this point in the history
  • Loading branch information
psobot committed Jul 15, 2023
1 parent 6dc9385 commit f13a93d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pedalboard/io/ReadableAudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ class ReadableAudioFile

if (!reader) {
std::ostringstream ss;
ss.imbue(std::locale(""));
try {
ss.imbue(std::locale(""));
} catch (const std::runtime_error &e) {
// On some systems (like Alpine Linux) we only have "C" and "POSIX"
// locales:
ss.imbue(std::locale("C"));
}

ss << "Failed to open audio file-like object: ";
ss << inputStream->getRepresentation();
Expand Down Expand Up @@ -521,7 +527,13 @@ class ReadableAudioFile
void throwReadError(long long currentPosition, long long numSamples,
long long samplesRead = -1) {
std::ostringstream ss;
ss.imbue(std::locale(""));
try {
ss.imbue(std::locale(""));
} catch (const std::runtime_error &e) {
// On some systems (like Alpine Linux) we only have "C" and "POSIX"
// locales:
ss.imbue(std::locale("C"));
}

ss << "Failed to read audio data";

Expand Down

0 comments on commit f13a93d

Please sign in to comment.