| 267 | } // namespace |
| 268 | |
| 269 | OmniVoiceResult OmniVoicePostprocessor::finalize( |
| 270 | const runtime::AudioBuffer & audio, |
| 271 | const OmniVoiceRequest & request) const { |
| 272 | auto mono = mono_from_audio(audio); |
| 273 | if (request.generation.postprocess_output) { |
| 274 | auto pcm = engine::audio::float_to_pcm16_clipped( |
| 275 | mono, |
| 276 | engine::audio::Pcm16QuantizeMode::RoundToNearest); |
| 277 | pcm = split_on_silence_pcm16(pcm, audio.sample_rate, 500, -50.0F, 500, 10); |
| 278 | pcm = trim_edges_pcm16(pcm, audio.sample_rate, 100, 100, -50.0F); |
| 279 | mono = engine::audio::pcm16_to_float_unit_range(pcm); |
| 280 | } |
| 281 | |
| 282 | if (request.reference_audio_tokens.has_value() && request.reference_rms < 0.1F && request.reference_rms > 0.0F) { |
| 283 | const float scale = request.reference_rms / 0.1F; |
| 284 | for (float & sample : mono) { |
| 285 | sample *= scale; |
| 286 | } |
| 287 | } else if (!request.reference_audio_tokens.has_value()) { |
| 288 | float peak = 0.0F; |
| 289 | for (const float sample : mono) { |
| 290 | peak = std::max(peak, std::abs(sample)); |
| 291 | } |
| 292 | if (peak > 1.0e-6F) { |
| 293 | const float scale = 0.5F / peak; |
| 294 | for (float & sample : mono) { |
| 295 | sample *= scale; |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | mono = fade_and_pad_audio(mono, audio.sample_rate); |
| 301 | OmniVoiceResult result; |
| 302 | result.audio = make_audio_buffer(std::move(mono), audio.sample_rate); |
| 303 | return result; |
| 304 | } |
| 305 | |
| 306 | } // namespace engine::models::omnivoice |
no test coverage detected