Skip to content

Mkulakow/audio format fix - #4637

Open
michalkulakowski wants to merge 1 commit into
mainfrom
mkulakow/audio_format_fix
Open

michalkulakowski wants to merge 1 commit into
mainfrom
mkulakow/audio_format_fix

Conversation

@michalkulakowski

@michalkulakowski michalkulakowski commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

🛠 Summary

#4613

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

Copilot AI balanced review requested due to automatic review settings October 7, 2026 08:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The implementation has portability, undefined-behavior, disabled-build, and oversized-test defects.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity

Open (3)
What changed in this PR

Updates text-to-speech responses to honor WAV/PCM formats and return matching content types.

Changes:

  • Converts generated audio to PCM16 WAV or raw PCM16.
  • Rejects unsupported response formats.
  • Adds custom HTTP content types and tests.
File Description
src/​audio/​audio_utils.cpp Implements PCM16 conversion and output.
src/​audio/​audio_utils.hpp Declares audio format utilities.
src/​audio/​text_to_speech/​t2s_calculator.cc Selects and validates response formats.
src/​http_rest_api_handler.cpp Assigns audio response content types.
src/​http_rest_api_handler.hpp Adds custom content-type support.
src/​http_server.cpp Emits custom HTTP content types.
src/​llm/​omni_model/​legacy/​servable.cpp Uses the updated WAV writer.
src/​test/​audio/​audio_utils_test.cpp Tests PCM16 output and limits.
src/​test/​audio/​text2speech_test.cpp Tests formats and content types.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/http_rest_api_handler.cpp Outdated
Comment thread src/audio/audio_utils.cpp
Comment thread src/test/audio/audio_utils_test.cpp
@michalkulakowski
michalkulakowski force-pushed the mkulakow/audio_format_fix branch from 3646061 to 9a6048e Compare October 13, 2026 14:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/audio/audio_utils.cpp
Comment on lines +337 to +343
*ppData = std::malloc(pDataSize);
if (*ppData == nullptr && pDataSize > 0) {
throw std::runtime_error("Failed to allocate raw PCM output buffer");
}
auto pcm16 = convertWaveformToPcm16(speechSize, waveformPtr);
std::memcpy(*ppData, pcm16.data(), pDataSize);
}
Comment thread src/audio/audio_utils.hpp

void prepareAudioOutput(void** ppData, size_t& pDataSize, uint32_t sampleRate, size_t speechSize, const float* waveformPtr);

void prepareRawPcm16LEOutput(void** ppData, size_t& pDataSize, size_t speechSize, const float* waveformPtr);
Comment on lines +160 to +168
auto responseFormat = ovms::audio_utils::TextToSpeechResponseFormat::WAV;
auto responseFormatIt = payload.parsedJson->FindMember("response_format");
if (responseFormatIt != payload.parsedJson->MemberEnd()) {
if (!responseFormatIt->value.IsString()) {
return absl::InvalidArgumentError("response_format field is not a string");
}
auto requestedFormat = ovms::audio_utils::tryParseTextToSpeechResponseFormat(responseFormatIt->value.GetString());
if (!requestedFormat.has_value()) {
return absl::InvalidArgumentError("Unsupported response_format. Supported formats are wav and pcm");
}
output = std::make_unique<std::string>(reinterpret_cast<char*>(ppData), pDataSize);
drwav_free(ppData, NULL);
std::free(ppData);
Comment on lines +88 to +89
EXPECT_EQ(responseComponents.contentType, ContentType::CUSTOM);
EXPECT_EQ(responseComponents.customContentType, "audio/wav");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants