| 128 | throw std::runtime_error("unknown VoxCPM2 session option: " + key); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | int64_t product(const std::vector<int64_t> &values) { |
| 133 | int64_t out = 1; |
| 134 | for (const int64_t value : values) { |
| 135 | if (value <= 0) { |
| 136 | throw std::runtime_error("VoxCPM2 AudioVAE decoder rate is invalid"); |
| 137 | } |
| 138 | out *= value; |
| 139 | } |
| 140 | return out; |
| 141 | } |
| 142 | |
| 143 | } // namespace |
| 144 | |
| 145 | bool VoxCPM2SessionBase::EncodedPromptCacheKeyEqual::operator()( |
| 146 | const EncodedPromptCacheKey &lhs, |
| 147 | const EncodedPromptCacheKey &rhs) const { |
| 148 | return lhs.prompt_text == rhs.prompt_text && |
| 149 | optional_audio_equal(lhs.prompt_audio, rhs.prompt_audio) && |
| 150 | optional_audio_equal(lhs.reference_audio, rhs.reference_audio); |
| 151 | } |
| 152 | |
| 153 | VoxCPM2SessionBase::VoxCPM2SessionBase(runtime::TaskSpec task, |
| 154 | runtime::SessionOptions options, |
| 155 | std::shared_ptr<const VoxCPM2Assets> assets) |
| 156 | : RuntimeSessionBase(options), task_(task), |
| 157 | assets_(require_assets(std::move(assets))), |
| 158 | encoded_prompt_cache_(prompt_cache_slots_from_options(options.options)) { |
| 159 | if (task_.mode != runtime::RunMode::Offline && |
| 160 | task_.mode != runtime::RunMode::Streaming) { |
| 161 | throw std::runtime_error( |
| 162 | "VoxCPM2 only supports offline and streaming sessions"); |
| 163 | } |
| 164 | if (task_.task != runtime::VoiceTaskKind::Tts) { |
| 165 | throw std::runtime_error("VoxCPM2 only supports the Tts task"); |
| 166 | } |
| 167 | |
| 168 | reject_enabled_denoise(options.options, {"voxcpm2.denoise"}); |
| 169 | reject_enabled_denoise(options.options, {"voxcpm2.load_denoiser"}); |
| 170 | reject_denoiser_option(options.options, {"voxcpm2.denoiser"}); |
| 171 | validate_session_options(options.options); |
| 172 | |
| 173 | generator_config_.weight_context_bytes = runtime::parse_size_mb_option( |
| 174 | options.options, {"voxcpm2.weight_context_mb"}, |
| 175 | generator_config_.weight_context_bytes); |
| 176 | generator_config_.text_embedding_graph_context_bytes = |
| 177 | runtime::parse_size_mb_option( |
| 178 | options.options, {"voxcpm2.text_embedding_graph_context_mb"}, |
| 179 | generator_config_.text_embedding_graph_context_bytes); |
| 180 | generator_config_.lm_step_graph_context_bytes = runtime::parse_size_mb_option( |
| 181 | options.options, {"voxcpm2.lm_step_graph_context_mb"}, |
| 182 | generator_config_.lm_step_graph_context_bytes); |
| 183 | generator_config_.projection_graph_context_bytes = |
| 184 | runtime::parse_size_mb_option( |
| 185 | options.options, {"voxcpm2.projection_graph_context_mb"}, |
| 186 | generator_config_.projection_graph_context_bytes); |
| 187 | generator_config_.local_encoder_graph_context_bytes = |
nothing calls this directly
no test coverage detected