| 64 | } |
| 65 | |
| 66 | std::vector<float> build_selected_prompt_features( |
| 67 | const VibeVoiceConnectorOutput & connected, |
| 68 | const std::vector<int64_t> & token_counts) { |
| 69 | if (connected.frames <= 0 || connected.hidden_size <= 0) { |
| 70 | throw std::runtime_error("VibeVoice prompt connector returned invalid shape"); |
| 71 | } |
| 72 | const int64_t speakers = static_cast<int64_t>(token_counts.size()); |
| 73 | if (speakers <= 0) { |
| 74 | return {}; |
| 75 | } |
| 76 | if (connected.frames % speakers != 0) { |
| 77 | throw std::runtime_error("VibeVoice prompt connector frame count is not divisible by speakers"); |
| 78 | } |
| 79 | const int64_t padded_frames = connected.frames / speakers; |
| 80 | std::vector<float> selected; |
| 81 | int64_t selected_frames = 0; |
| 82 | for (const int64_t count : token_counts) { |
| 83 | if (count < 0 || count > padded_frames) { |
| 84 | throw std::runtime_error("VibeVoice prompt speech mask exceeds acoustic connector frames"); |
| 85 | } |
| 86 | selected_frames += count; |
| 87 | } |
| 88 | selected.reserve(static_cast<size_t>(selected_frames * connected.hidden_size)); |
| 89 | for (int64_t speaker = 0; speaker < speakers; ++speaker) { |
| 90 | const int64_t count = token_counts[static_cast<size_t>(speaker)]; |
| 91 | for (int64_t frame = 0; frame < count; ++frame) { |
| 92 | const size_t base = static_cast<size_t>( |
| 93 | (speaker * padded_frames + frame) * connected.hidden_size); |
| 94 | selected.insert( |
| 95 | selected.end(), |
| 96 | connected.values.begin() + static_cast<std::ptrdiff_t>(base), |
| 97 | connected.values.begin() + static_cast<std::ptrdiff_t>(base + static_cast<size_t>(connected.hidden_size))); |
| 98 | } |
| 99 | } |
| 100 | return selected; |
| 101 | } |
| 102 | |
| 103 | void splice_speech_embeddings( |
| 104 | std::vector<float> & embeddings, |
no test coverage detected