Voice_Assistant.AXERA / zipvoice_cpp_server /zipvoice_resident_server.hpp
HY-2012's picture
Upload ASR and TTS models
a37072b verified
Raw History Blame Contribute Delete
2.16 kB
#pragma once
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <sys/time.h>
#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<int> prompt_tokens;
std::vector<float> 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> tokenizer_;
std::unique_ptr<ZipVoiceEngine> engine_;
std::unique_ptr<Vocoder> vocoder_;
std::map<std::string, ZipVoicePromptCache> prompts_;
};