| 1960 | } |
| 1961 | |
| 1962 | OmniVoiceAudioTokens run(const NormalizedReferenceAudio & audio) { |
| 1963 | const int64_t actual_frames = audio.frames; |
| 1964 | if (static_cast<int64_t>(audio.acoustic_samples_24k.size()) > acoustic_sample_capacity_ || |
| 1965 | static_cast<int64_t>(audio.semantic_samples_16k_padded.size()) > semantic_sample_capacity_ || |
| 1966 | actual_frames > frame_capacity_) { |
| 1967 | throw std::runtime_error("OmniVoice audio-tokenizer encoder request exceeds prepared capacity"); |
| 1968 | } |
| 1969 | std::vector<float> acoustic_padded(static_cast<size_t>(acoustic_sample_capacity_), 0.0F); |
| 1970 | std::copy(audio.acoustic_samples_24k.begin(), audio.acoustic_samples_24k.end(), acoustic_padded.begin()); |
| 1971 | core::write_tensor_f32(acoustic_input_, acoustic_padded); |
| 1972 | std::vector<float> semantic_padded(static_cast<size_t>(semantic_sample_capacity_), 0.0F); |
| 1973 | std::copy(audio.semantic_samples_16k_padded.begin(), audio.semantic_samples_16k_padded.end(), semantic_padded.begin()); |
| 1974 | core::write_tensor_f32(semantic_input_, semantic_padded); |
| 1975 | std::vector<int32_t> downsample(static_cast<size_t>(frame_capacity_), 0); |
| 1976 | for (int64_t i = 0; i < actual_frames; ++i) { |
| 1977 | downsample[static_cast<size_t>(i)] = static_cast<int32_t>(i * semantic_downsample_factor_); |
| 1978 | } |
| 1979 | core::write_tensor_i32(downsample_indices_, downsample); |
| 1980 | tensor_writer_.flush(); |
| 1981 | core::set_backend_threads(backend_, compute_threads_); |
| 1982 | const ggml_status status = engine::core::compute_backend_graph(backend_, graph_); |
| 1983 | ggml_backend_synchronize(backend_); |
| 1984 | if (status != GGML_STATUS_SUCCESS) { |
| 1985 | throw std::runtime_error("OmniVoice audio-tokenizer encoder graph compute failed"); |
| 1986 | } |
| 1987 | OmniVoiceAudioTokens tokens = {}; |
| 1988 | tokens.frames = actual_frames; |
| 1989 | tokens.codebooks = static_cast<int64_t>(code_outputs_.size()); |
| 1990 | tokens.reference_rms = audio.reference_rms; |
| 1991 | tokens.token_ids.assign(static_cast<size_t>(actual_frames * tokens.codebooks), 0); |
| 1992 | for (size_t codebook = 0; codebook < code_outputs_.size(); ++codebook) { |
| 1993 | std::vector<int32_t> values(static_cast<size_t>(frame_capacity_), 0); |
| 1994 | ggml_backend_tensor_get( |
| 1995 | code_outputs_[codebook], |
| 1996 | values.data(), |
| 1997 | 0, |
| 1998 | values.size() * sizeof(int32_t)); |
| 1999 | for (int64_t frame = 0; frame < actual_frames; ++frame) { |
| 2000 | tokens.token_ids[static_cast<size_t>(frame * tokens.codebooks + static_cast<int64_t>(codebook))] = |
| 2001 | values[static_cast<size_t>(frame)]; |
| 2002 | } |
| 2003 | } |
| 2004 | return tokens; |
| 2005 | } |
| 2006 | |
| 2007 | int64_t frame_capacity() const noexcept { return frame_capacity_; } |
| 2008 | int64_t acoustic_sample_capacity() const noexcept { return acoustic_sample_capacity_; } |
no test coverage detected