| 51 | } // namespace |
| 52 | |
| 53 | MioCodecSession::MioCodecSession( |
| 54 | const runtime::TaskSpec & task, |
| 55 | const runtime::SessionOptions & options, |
| 56 | std::shared_ptr<const MioCodecAssets> assets) |
| 57 | : runtime::RuntimeSessionBase(options), |
| 58 | task_(task), |
| 59 | assets_(std::move(assets)) { |
| 60 | if (assets_ == nullptr) { |
| 61 | throw std::runtime_error("MioCodec session requires loaded assets"); |
| 62 | } |
| 63 | if (task_.mode != runtime::RunMode::Offline) { |
| 64 | throw std::runtime_error("MioCodec only supports offline sessions"); |
| 65 | } |
| 66 | if (task_.task != runtime::VoiceTaskKind::VoiceConversion |
| 67 | && task_.task != runtime::VoiceTaskKind::SpeechToSpeech) { |
| 68 | throw std::runtime_error("MioCodec supports VoiceConversion or SpeechToSpeech tasks"); |
| 69 | } |
| 70 | |
| 71 | const size_t weight_context_bytes = runtime::parse_size_mb_option( |
| 72 | options.options, |
| 73 | {"miocodec.weight_context_mb", "weight_context_mb"}, |
| 74 | kDefaultCodecWeightContextBytes); |
| 75 | const auto weight_storage_type = parse_miocodec_weight_type(options); |
| 76 | codec_weights_ = load_miocodec_weights( |
| 77 | *assets_->model_weights, |
| 78 | execution_context(), |
| 79 | weight_context_bytes, |
| 80 | assets_->config, |
| 81 | weight_storage_type); |
| 82 | engine::modules::WavlmEncoderConfig wavlm_config; |
| 83 | wavlm_config.output_hidden_layer = 9; |
| 84 | wavlm_config.weight_storage_type = weight_storage_type; |
| 85 | auto local_ssl_wavlm = engine::modules::WavlmEncoderComponent::load_from_tensor_source( |
| 86 | *assets_->wavlm_weights, |
| 87 | options.backend, |
| 88 | wavlm_config); |
| 89 | auto global_ssl_wavlm = engine::modules::WavlmEncoderComponent(local_ssl_wavlm.weights(), options.backend, true); |
| 90 | const size_t constant_context_bytes = runtime::parse_size_mb_option( |
| 91 | options.options, |
| 92 | {"miocodec.constant_context_mb", "constant_context_mb"}, |
| 93 | kDefaultConstantContextBytes); |
| 94 | const size_t content_graph_arena_bytes = runtime::parse_size_mb_option( |
| 95 | options.options, |
| 96 | {"miocodec.content_graph_arena_mb", "graph_arena_mb"}, |
| 97 | kDefaultContentGraphArenaBytes); |
| 98 | const size_t global_graph_arena_bytes = runtime::parse_size_mb_option( |
| 99 | options.options, |
| 100 | {"miocodec.global_graph_arena_mb"}, |
| 101 | kDefaultGlobalGraphArenaBytes); |
| 102 | const size_t wave_graph_arena_bytes = runtime::parse_size_mb_option( |
| 103 | options.options, |
| 104 | {"miocodec.wave_graph_arena_mb"}, |
| 105 | kDefaultWaveGraphArenaBytes); |
| 106 | content_encoder_ = std::make_unique<MioCodecContentEncoderRuntime>( |
| 107 | assets_, |
| 108 | codec_weights_, |
| 109 | execution_context(), |
| 110 | content_graph_arena_bytes, |
nothing calls this directly
no test coverage detected