Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pocket_tts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ struct Config {
std::string models_dir = "models", tokenizer_path = "models/tokenizer.model";
std::string voices_dir = "voices";
std::string precision = "int8";
uint64_t seed = 0;
float temperature = 0.7f;
float eos_threshold = -4.0f;
float noise_clamp = 0.0f;
Expand Down Expand Up @@ -217,6 +218,8 @@ float normal(float mean = 0, float stddev = 1) {
void fill_normal(float* data, size_t n, float mean = 0, float stddev = 1) {
for (size_t i = 0; i < n; ++i) data[i] = normal(mean, stddev);
}

void set_seed(uint64_t new_seed) { seed(new_seed == 0 ? uint64_t(std::chrono::high_resolution_clock::now().time_since_epoch().count()) : new_seed); }
} // namespace rng

// ── Audio Resampling (Lanczos) ──────────────────────────────────────────────
Expand Down Expand Up @@ -1396,7 +1399,7 @@ class PocketTTS {
static constexpr int SR = 24000;

explicit PocketTTS(const Config& cfg = {}) : cfg_(cfg) {
rng::seed(uint64_t(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
rng::set_seed(cfg.seed);
tok_ = std::make_unique<Tokenizer>(cfg_.tokenizer_path);

// Thread budget: --threads sets the total. During pipelined streaming,
Expand Down Expand Up @@ -2603,8 +2606,10 @@ struct ptt_stream_ctx {
bool aborted = false;
};

void* ptt_stream_start(void* handle, const char* text, const char* voice) {
void* ptt_stream_start(void* handle, const char* text, const char* voice, uint64_t seed) {
if (!handle || !text || !voice) return nullptr;
pocket_tts::rng::set_seed(seed);

auto* tts = static_cast<pocket_tts::PocketTTS*>(handle);
auto* ctx = new ptt_stream_ctx();

Expand Down Expand Up @@ -2702,6 +2707,7 @@ int main(int argc, char* argv[]) {
" " << argv[0] << " --server [OPTIONS]\n"
"\nOptions:\n"
" --precision <int8|fp32> Model precision (default: int8)\n"
" --seed <ulong> Inference seed (default: 0 = random)\n"
" --temperature <float> Sampling temperature (default: 0.7)\n"
" --lsd-steps <int> Flow matching steps (default: 1)\n"
" --threads <int> Total thread budget (default: 0 = half cores)\n"
Expand All @@ -2724,6 +2730,7 @@ int main(int argc, char* argv[]) {
return 0;
}
else if (a == "--precision") cfg.precision = next();
else if (a == "--seed") cfg.seed = std::stoul(next());
else if (a == "--temperature") cfg.temperature = std::stof(next());
else if (a == "--lsd-steps") cfg.lsd_steps = std::stoi(next());
else if (a == "--threads") cfg.num_threads = std::stoi(next());
Expand Down