From c43d4e6c5db80ae32e307f9ad5f0ba23e195fe26 Mon Sep 17 00:00:00 2001 From: Alexis Brooks <91137432+0xAlexisSys@users.noreply.github.com> Date: Sat, 9 May 2026 13:36:06 +0600 Subject: [PATCH 1/2] Add seed option --- pocket_tts.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pocket_tts.cpp b/pocket_tts.cpp index 6b6b48a..2efed8a 100644 --- a/pocket_tts.cpp +++ b/pocket_tts.cpp @@ -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; @@ -1396,7 +1397,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::seed(cfg.seed == 0 ? uint64_t(std::chrono::high_resolution_clock::now().time_since_epoch().count()) : cfg.seed); tok_ = std::make_unique(cfg_.tokenizer_path); // Thread budget: --threads sets the total. During pipelined streaming, @@ -2557,13 +2558,14 @@ extern "C" { void* ptt_create(const char* models_dir, const char* voices_dir, const char* tokenizer_path, const char* precision, - float temperature, int lsd_steps, int num_threads) { + uint64_t seed, float temperature, int lsd_steps, int num_threads) { try { pocket_tts::Config cfg; if (models_dir) cfg.models_dir = models_dir; if (voices_dir) cfg.voices_dir = voices_dir; if (tokenizer_path) cfg.tokenizer_path = tokenizer_path; if (precision) cfg.precision = precision; + cfg.seed = seed; cfg.temperature = temperature; cfg.lsd_steps = lsd_steps; cfg.num_threads = num_threads; @@ -2702,6 +2704,7 @@ int main(int argc, char* argv[]) { " " << argv[0] << " --server [OPTIONS]\n" "\nOptions:\n" " --precision Model precision (default: int8)\n" + " --seed Inference seed (default: 0 = random)\n" " --temperature Sampling temperature (default: 0.7)\n" " --lsd-steps Flow matching steps (default: 1)\n" " --threads Total thread budget (default: 0 = half cores)\n" @@ -2724,6 +2727,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()); From 4c0ce671000fa56142a3a64fead6dc3b224e843f Mon Sep 17 00:00:00 2001 From: Alexis Brooks <91137432+0xAlexisSys@users.noreply.github.com> Date: Sun, 10 May 2026 11:46:48 +0600 Subject: [PATCH 2/2] Move FFI seed option to `ptt_stream_start` --- pocket_tts.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pocket_tts.cpp b/pocket_tts.cpp index 2efed8a..9366093 100644 --- a/pocket_tts.cpp +++ b/pocket_tts.cpp @@ -218,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) ────────────────────────────────────────────── @@ -1397,7 +1399,7 @@ class PocketTTS { static constexpr int SR = 24000; explicit PocketTTS(const Config& cfg = {}) : cfg_(cfg) { - rng::seed(cfg.seed == 0 ? uint64_t(std::chrono::high_resolution_clock::now().time_since_epoch().count()) : cfg.seed); + rng::set_seed(cfg.seed); tok_ = std::make_unique(cfg_.tokenizer_path); // Thread budget: --threads sets the total. During pipelined streaming, @@ -2558,14 +2560,13 @@ extern "C" { void* ptt_create(const char* models_dir, const char* voices_dir, const char* tokenizer_path, const char* precision, - uint64_t seed, float temperature, int lsd_steps, int num_threads) { + float temperature, int lsd_steps, int num_threads) { try { pocket_tts::Config cfg; if (models_dir) cfg.models_dir = models_dir; if (voices_dir) cfg.voices_dir = voices_dir; if (tokenizer_path) cfg.tokenizer_path = tokenizer_path; if (precision) cfg.precision = precision; - cfg.seed = seed; cfg.temperature = temperature; cfg.lsd_steps = lsd_steps; cfg.num_threads = num_threads; @@ -2605,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(handle); auto* ctx = new ptt_stream_ctx();