Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/cli/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ engine::runtime::AudioBuffer read_voice_ref(
if (bytes.size() > kMaxVoiceRefBytes) {
throw InvalidRequestError("voice_ref base64 data exceeds the 5 MiB limit");
}
return read_audio_buffer(std::string_view(reinterpret_cast<const char *>(bytes.data()), bytes.size()));
try {
return read_audio_buffer(std::string_view(reinterpret_cast<const char *>(bytes.data()), bytes.size()));
} catch (const std::runtime_error & error) {
throw InvalidRequestError(std::string("voice_ref base64 data is not a readable WAV (") + error.what() + ")");
}
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion app/server/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ path, `{"type": "path", "path": "..."}`, or `{"type": "base64", "data": "..."}`
with a Base64-encoded WAV or `data:audio/wav;base64,...` URI of at most 5 MiB.
The inline form lets a client send a reference voice, for example the target
speaker of a voice conversion, without the server having to store it on disk.
An invalid `voice_ref` returns HTTP 400. CLI request files and the batch and
A malformed `voice_ref`, or inline data that is not a readable WAV, returns HTTP 400. CLI request files and the batch and
stream endpoints share this request format, so they accept it too.

A result's artifacts (opaque payloads such as speaker embeddings or acoustic
Expand Down
5 changes: 5 additions & 0 deletions tests/unittests/test_cli_request_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ void test_request_json_voice_ref() {
require_voice_ref_rejected("{\"type\":\"base64\"}", "needs a data string");
require_voice_ref_rejected("{\"type\":\"base64\",\"data\":\"@@@@\"}", "not valid base64");
require_voice_ref_rejected("{\"type\":\"base64\",\"data\":\"\"}", "empty payload");
const std::string not_wav = "plain text, not a WAV file";
require_voice_ref_rejected(
"{\"type\":\"base64\",\"data\":\"" +
minitts::app::base64_encode(std::vector<uint8_t>(not_wav.begin(), not_wav.end())) + "\"}",
"not a readable WAV");
require_voice_ref_rejected(
"{\"type\":\"base64\",\"data\":\"" + std::string(size_t{8} * 1024 * 1024, 'A') + "\"}", "5 MiB limit");
}
Expand Down
Loading