MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / MioTTSSession

Method MioTTSSession

src/models/miotts/session.cpp:563–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561} // namespace
562
563MioTTSSession::MioTTSSession(
564 const runtime::TaskSpec & task,
565 const runtime::SessionOptions & options,
566 std::shared_ptr<const MioTTSAssets> assets)
567 : runtime::RuntimeSessionBase(options),
568 task_(task),
569 assets_(require_assets(std::move(assets))) {
570 if (task_.task != runtime::VoiceTaskKind::Tts) {
571 throw std::runtime_error("MioTTS only supports VoiceTaskKind::Tts");
572 }
573 if (task_.mode != runtime::RunMode::Offline) {
574 throw std::runtime_error("MioTTS currently supports offline sessions");
575 }
576 const auto lm_weight_type = option_weight_type(options, "miotts.weight_type", engine::assets::TensorStorageType::Native);
577 validate_matmul_weight_storage(lm_weight_type, "miotts.weight_type");
578 text_chunk_size_ = engine::text::parse_text_chunk_size_override(options.options)
579 .value_or(kReferenceTextChunkCodepoints);
580 if (const auto value = runtime::find_option(options.options, {"miotts.best_of_n_enabled"})) {
581 best_of_n_enabled_ = runtime::parse_bool_option(*value, "miotts.best_of_n_enabled");
582 }
583 best_of_n_default_ = runtime::parse_int_option(options.options, {"miotts.best_of_n_default"})
584 .value_or(1);
585 best_of_n_max_ = runtime::parse_int_option(options.options, {"miotts.best_of_n_max"})
586 .value_or(8);
587 if (best_of_n_default_ <= 0) {
588 throw std::runtime_error("MioTTS best_of_n_default must be positive");
589 }
590 if (best_of_n_max_ <= 0) {
591 throw std::runtime_error("MioTTS best_of_n_max must be positive");
592 }
593 if (best_of_n_default_ > best_of_n_max_) {
594 best_of_n_default_ = best_of_n_max_;
595 }
596 best_of_n_language_ = normalized_best_of_n_language(
597 runtime::find_option(options.options, {"miotts.best_of_n_language"}).value_or("auto"));
598 best_of_n_asr_model_path_ = resolve_best_of_n_asr_model_path(options, *assets_);
599 tokenizer_ = std::make_unique<MioTTSTokenizer>(assets_);
600 language_model_ = std::make_unique<MioTTSCausalLMRuntime>(
601 assets_,
602 execution_context(),
603 runtime::parse_size_mb_option(options.options, {"miotts.prefill_graph_arena_mb"}, kDefaultLmPrefillGraphArenaBytes),
604 runtime::parse_size_mb_option(options.options, {"miotts.decode_graph_arena_mb"}, kDefaultLmDecodeGraphArenaBytes),
605 runtime::parse_size_mb_option(options.options, {"miotts.weight_context_mb"}, kDefaultLmWeightContextBytes),
606 lm_weight_type);
607 assets_->model_weights->release_storage();
608
609 const auto codec_model_path = resolve_codec_model_path(options, *assets_);
610 engine::debug::trace_log_scalar("miotts.codec_model_path", codec_model_path.string());
611 codec_assets_ = miocodec::load_miocodec_assets(codec_model_path);
612 codec_weights_ = miocodec::load_miocodec_weights(
613 *codec_assets_->model_weights,
614 execution_context(),
615 runtime::parse_size_mb_option(options.options, {"miotts.codec_weight_context_mb"}, kDefaultCodecWeightContextBytes),
616 codec_assets_->config);
617 engine::modules::WavlmEncoderConfig wavlm_config;
618 wavlm_config.output_hidden_layer = 9;
619 wavlm_config.weight_storage_type = lm_weight_type;
620 auto wavlm = engine::modules::WavlmEncoderComponent::load_from_tensor_source(

Callers

nothing calls this directly

Calls 15

find_optionFunction · 0.85
parse_bool_optionFunction · 0.85
parse_int_optionFunction · 0.85
parse_size_mb_optionFunction · 0.85
resolve_codec_model_pathFunction · 0.85
load_miocodec_assetsFunction · 0.85
load_miocodec_weightsFunction · 0.85
require_assetsFunction · 0.70
option_weight_typeFunction · 0.70

Tested by

no test coverage detected