#pragma once #include #include #include #include #include #include "ax_sys_api.h" #include "src/tokenizer.hpp" #include "src/fbank.hpp" #include "src/zipvoice_engine.hpp" #include "src/vocoder.hpp" struct ZipVoicePromptCache { std::string key; // zh / en std::string prompt_text; std::string prompt_wav; std::vector prompt_tokens; std::vector prompt_features; // [1, T, 100] flattened int prompt_frames = 0; float prompt_rms = 0.0f; }; struct ZipVoiceRequest { std::string id; std::string text; std::string prompt = "zh"; float speed = 1.0f; int num_step = 0; // 0 = use server default std::string output_wav; }; struct ZipVoiceResponse { bool ok = false; std::string id; std::string path; std::string error; double wall_sec = 0.0; double model_sec = 0.0; double rtf = 0.0; }; class ZipVoiceResidentServer { public: ZipVoiceResidentServer(); ~ZipVoiceResidentServer(); bool Init(const std::string& root_dir, const std::string& model_dir, const std::string& token_file, const std::string& vocoder_model, int max_tokens = 384, int max_feat_len = 1024, int num_step = 4, float default_speed = 1.0f, int seed = 42); ZipVoiceResponse Infer(const ZipVoiceRequest& req); bool CachePrompt(const std::string& key, const std::string& wav_path, const std::string& text); private: bool InitAxSys(); bool LoadTokenizer(); bool LoadRuntime(); bool LoadVocoder(); bool CachePrompts(); private: std::string root_dir_; std::string model_dir_; std::string token_file_; std::string vocoder_model_; int max_tokens_ = 384; int max_feat_len_ = 1024; int num_step_ = 4; float default_speed_ = 1.0f; int seed_ = 42; bool ax_inited_ = false; std::unique_ptr tokenizer_; std::unique_ptr engine_; std::unique_ptr vocoder_; std::map prompts_; };