voice_audio_multi/include/engine/community_models/moss_voicegen/session.h
Fabio c36510c21e
Some checks failed
Linux Build / Linux cpu (push) Has been cancelled
Linux Build / Linux cpu-clang (push) Has been cancelled
Linux Build / Linux vulkan (push) Has been cancelled
mac-build / macOS CPU (push) Has been cancelled
Nix Build / Nix (cpu) (push) Has been cancelled
Nix Build / Nix (vulkan) (push) Has been cancelled
windows-build / Windows CPU (push) Has been cancelled
Initial import: audio.cpp with Orange Pi documentation
2026-11-04 19:05:22 +01:00

80 lines
3.4 KiB
C++

#pragma once
#include "engine/community_models/moss_voicegen/assets.h"
#include "engine/framework/decoders/moss_tts_delay/backbone.h"
#include "engine/framework/decoders/moss_tts_delay/delay_decoder.h"
#include "engine/framework/decoders/moss_tts_delay/heads.h"
#include "engine/community_models/moss_voicegen/tokenizer_text.h"
#include "engine/framework/core/execution_context.h"
#include "engine/framework/codecs/moss_audio_tokenizer_codec_runtime.h"
#include "engine/framework/modules/multi_codebook_embedding.h"
#include "engine/framework/runtime/session_base.h"
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
namespace engine::models::moss_voicegen {
class MossVoiceGenSession final
: public runtime::RuntimeSessionBase
, public runtime::IOfflineVoiceTaskSession {
public:
MossVoiceGenSession(
runtime::TaskSpec task,
runtime::SessionOptions options,
std::shared_ptr<const MossVoiceGenAssets> assets);
~MossVoiceGenSession() override;
std::string family() const override;
runtime::VoiceTaskKind task_kind() const override;
runtime::RunMode run_mode() const override;
void prepare(const runtime::SessionPreparationRequest & request) override;
runtime::TaskResult run(const runtime::TaskRequest & request) override;
private:
struct GeneratedChunk {
std::vector<int32_t> codes; // [n_vq, frames] row-major
int64_t codebooks = 0;
int64_t frames = 0;
bool started_audio = false;
bool hit_frame_ceiling = false;
};
GeneratedChunk generate_chunk(
const std::string & text,
const std::string & instruction,
const std::optional<std::string> & language,
const decoders::MossTtsDelaySamplingOptions & sampling,
uint32_t seed,
decoders::MossTtsDelayLengthBounds bounds_override);
std::vector<float> decode_codes(const GeneratedChunk & chunk);
runtime::TaskSpec task_;
std::shared_ptr<const MossVoiceGenAssets> assets_;
engine::assets::TensorStorageType weight_storage_type_ = engine::assets::TensorStorageType::BF16;
size_t backbone_graph_arena_bytes_ = 512ull * 1024ull * 1024ull;
#if defined(INTPTR_MAX) && (INTPTR_MAX == INT32_MAX)
size_t backbone_weight_context_bytes_ = 1024ull * 1024ull * 1024ull;
size_t heads_graph_arena_bytes_ = 256ull * 1024ull * 1024ull;
size_t heads_weight_context_bytes_ = 1024ull * 1024ull * 1024ull;
size_t codec_graph_arena_bytes_ = 2048ull * 1024ull * 1024ull;
size_t codec_weight_context_bytes_ = 1024ull * 1024ull * 1024ull;
#else
size_t backbone_weight_context_bytes_ = 8192ull * 1024ull * 1024ull;
size_t heads_graph_arena_bytes_ = 256ull * 1024ull * 1024ull;
size_t heads_weight_context_bytes_ = 4096ull * 1024ull * 1024ull;
size_t codec_graph_arena_bytes_ = 2048ull * 1024ull * 1024ull;
size_t codec_weight_context_bytes_ = 4096ull * 1024ull * 1024ull;
#endif
// The execution context comes from RuntimeSessionBase; the runtimes below borrow it.
std::unique_ptr<MossVoiceGenTextProcessor> text_processor_;
std::unique_ptr<engine::modules::MultiCodebookEmbedding> codebooks_;
std::unique_ptr<decoders::MossTtsDelayBackboneRuntime> backbone_;
std::unique_ptr<decoders::MossTtsDelayHeadsRuntime> heads_;
std::unique_ptr<engine::codecs::MossAudioTokenizerCodecRuntime> codec_;
};
} // namespace engine::models::moss_voicegen