| 330 | const int64_t start = partial_index * frame_step; |
| 331 | for (int64_t frame = 0; frame < weights_->config.partial_frames; ++frame) { |
| 332 | const float * src = padded.data() + static_cast<ptrdiff_t>((start + frame) * weights_->config.num_mels); |
| 333 | float * dst = partials.data() + static_cast<ptrdiff_t>(((partial_index * weights_->config.partial_frames) + frame) * weights_->config.num_mels); |
| 334 | std::copy(src, src + weights_->config.num_mels, dst); |
| 335 | } |
| 336 | } |
| 337 | for (int64_t partial_index = 0; partial_index < n_partials; ++partial_index) { |
| 338 | const float * partial_ptr = partials.data() + static_cast<ptrdiff_t>( |
| 339 | partial_index * weights_->config.partial_frames * weights_->config.num_mels); |
| 340 | std::vector<float> partial( |
| 341 | partial_ptr, |
| 342 | partial_ptr + static_cast<ptrdiff_t>(weights_->config.partial_frames * weights_->config.num_mels)); |
| 343 | std::vector<float> hidden; |
| 344 | auto layer_out = run_lstm_layer( |
| 345 | weights_->lstm_layers[0], |
| 346 | weights_->config.num_mels, |
| 347 | weights_->config.hidden_size, |
| 348 | partial, |
| 349 | weights_->config.partial_frames, |
| 350 | hidden); |
| 351 | layer_out = run_lstm_layer( |
| 352 | weights_->lstm_layers[1], |
| 353 | weights_->config.hidden_size, |
| 354 | weights_->config.hidden_size, |
| 355 | layer_out, |
| 356 | weights_->config.partial_frames, |
| 357 | hidden); |
| 358 | layer_out = run_lstm_layer( |
| 359 | weights_->lstm_layers[2], |
| 360 | weights_->config.hidden_size, |
| 361 | weights_->config.hidden_size, |
| 362 | layer_out, |
| 363 | weights_->config.partial_frames, |
| 364 | hidden); |
| 365 | const auto embed = project_embedding(*weights_, hidden); |
| 366 | utterance_embeds.insert(utterance_embeds.end(), embed.begin(), embed.end()); |
| 367 | } |
| 368 | std::vector<float> mean_embed(static_cast<size_t>(weights_->config.speaker_embed_size), 0.0f); |
| 369 | for (int64_t partial_index = 0; partial_index < n_partials; ++partial_index) { |
| 370 | const float * embed = utterance_embeds.data() + static_cast<ptrdiff_t>(partial_index * weights_->config.speaker_embed_size); |
| 371 | for (int64_t i = 0; i < weights_->config.speaker_embed_size; ++i) { |
| 372 | mean_embed[static_cast<size_t>(i)] += embed[i]; |
| 373 | } |
| 374 | } |
| 375 | for (float & value : mean_embed) { |
| 376 | value /= static_cast<float>(n_partials); |
| 377 | } |
| 378 | return l2_normalize(mean_embed); |
| 379 | } |
| 380 | |
| 381 | } // namespace engine::models::chatterbox |
no test coverage detected