| 2276 | } |
| 2277 | |
| 2278 | OmniVoiceAudioTokens OmniVoiceAudioTokenizerRuntime::encode_reference_audio( |
| 2279 | const runtime::AudioBuffer & audio, |
| 2280 | const OmniVoiceReferenceAudioOptions & options) { |
| 2281 | const auto normalized = normalize_reference_audio(audio, impl_->assets->config.audio_tokenizer, options); |
| 2282 | const auto acoustic_samples = |
| 2283 | pad_acoustic_input_if_needed(normalized.acoustic_samples_24k, impl_->assets->config.audio_tokenizer, normalized.frames); |
| 2284 | const int64_t semantic_frames = semantic_feature_frames( |
| 2285 | impl_->assets->config.audio_tokenizer, |
| 2286 | static_cast<int64_t>(normalized.semantic_samples_16k_padded.size())); |
| 2287 | const int64_t downsample_factor = semantic_downsample_factor(impl_->assets->config.audio_tokenizer); |
| 2288 | if (semantic_frames != normalized.frames * downsample_factor) { |
| 2289 | throw std::runtime_error("OmniVoice semantic feature extractor frame count does not match reference downsample ratio"); |
| 2290 | } |
| 2291 | impl_->last_stats.encoder_graph_rebuilt = false; |
| 2292 | impl_->last_stats.encoder_rebuild_ms = 0.0; |
| 2293 | if (impl_->encoder_graph == nullptr || |
| 2294 | !impl_->encoder_graph->matches( |
| 2295 | static_cast<int64_t>(acoustic_samples.size()), |
| 2296 | static_cast<int64_t>(normalized.semantic_samples_16k_padded.size()), |
| 2297 | normalized.frames, |
| 2298 | impl_->execution_context->backend(), |
| 2299 | impl_->execution_context->config().threads)) { |
| 2300 | const auto rebuild_start = Clock::now(); |
| 2301 | impl_->encoder_graph.reset(); |
| 2302 | impl_->encoder_graph = std::make_unique<EncoderGraph>( |
| 2303 | impl_->assets, |
| 2304 | impl_->weights, |
| 2305 | *impl_->execution_context, |
| 2306 | impl_->graph_arena_bytes, |
| 2307 | static_cast<int64_t>(acoustic_samples.size()), |
| 2308 | static_cast<int64_t>(normalized.semantic_samples_16k_padded.size()), |
| 2309 | normalized.frames); |
| 2310 | const auto rebuild_end = Clock::now(); |
| 2311 | impl_->last_stats.encoder_graph_rebuilt = true; |
| 2312 | impl_->last_stats.encoder_rebuild_ms = engine::debug::elapsed_ms(rebuild_start, rebuild_end); |
| 2313 | } |
| 2314 | impl_->last_stats.encoder_frame_capacity = impl_->encoder_graph->frame_capacity(); |
| 2315 | impl_->last_stats.encoder_acoustic_sample_capacity = impl_->encoder_graph->acoustic_sample_capacity(); |
| 2316 | impl_->last_stats.encoder_semantic_sample_capacity = impl_->encoder_graph->semantic_sample_capacity(); |
| 2317 | NormalizedReferenceAudio graph_audio = normalized; |
| 2318 | graph_audio.acoustic_samples_24k = acoustic_samples; |
| 2319 | return impl_->encoder_graph->run(graph_audio); |
| 2320 | } |
| 2321 | |
| 2322 | runtime::AudioBuffer OmniVoiceAudioTokenizerRuntime::decode_audio_tokens( |
| 2323 | const OmniVoiceGeneratedAudioTokens & audio_tokens) { |
no test coverage detected