Skip to content

Commit b0a8d11

Browse files
committed
add tts max length for kokoro (+1 squashed commits)
Squashed commits: [c1c6feaf] add tts max length for kokoro
1 parent 0e2b031 commit b0a8d11

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

koboldcpp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
extra_images_max = 4
6565

6666
# global vars
67-
KcppVersion = "1.98"
67+
KcppVersion = "1.98.1"
6868
showdebug = True
6969
kcpp_instance = None #global running instance
7070
global_memory = {"tunnel_url": "", "restart_target":"", "input_to_exit":False, "load_complete":False, "restart_override_config_target":""}

otherarch/tts_adapter.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,32 @@ std::string trim_words(const std::string& input, const std::string& separator, s
478478
return result.str();
479479
}
480480

481+
static std::string TruncateToFirstNumberWords(const std::string& input, int limit) {
482+
static const std::regex wordRegex(R"(\b[\w'-]+\b)");
483+
std::sregex_iterator words_begin(input.begin(), input.end(), wordRegex);
484+
std::sregex_iterator words_end;
485+
int count = 0;
486+
std::size_t cutoffPos = std::string::npos;
487+
if(limit<=0)
488+
{
489+
return "";
490+
}
491+
for (auto it = words_begin; it != words_end; ++it) {
492+
++count;
493+
if (count >= limit) {
494+
// position AFTER the last matched word
495+
cutoffPos = it->position() + it->length();
496+
break;
497+
}
498+
}
499+
if (cutoffPos == std::string::npos) {
500+
// fewer than N words, return original
501+
return input;
502+
}
503+
// Preserve everything up to and including the Nth word
504+
return input.substr(0, cutoffPos);
505+
}
506+
481507
static llama_context * ttc_ctx = nullptr; //text to codes ctx
482508
static llama_context * cts_ctx = nullptr; //codes to speech
483509

@@ -562,6 +588,7 @@ bool ttstype_load_model(const tts_load_model_inputs inputs)
562588
}
563589

564590
ttsdebugmode = inputs.debugmode;
591+
tts_max_len = inputs.ttsmaxlen;
565592

566593
// tts init
567594
if (is_ttscpp_file) {
@@ -577,8 +604,6 @@ bool ttstype_load_model(const tts_load_model_inputs inputs)
577604

578605
nthreads = inputs.threads;
579606

580-
tts_max_len = inputs.ttsmaxlen;
581-
582607
tts_model_params.use_mmap = false;
583608
tts_model_params.use_mlock = false;
584609
tts_model_params.n_gpu_layers = inputs.gpulayers; //offload if possible
@@ -692,6 +717,11 @@ static tts_generation_outputs ttstype_generate_ttscpp(const tts_generation_input
692717
}
693718
}
694719

720+
if(tts_max_len>0)
721+
{
722+
prompt = TruncateToFirstNumberWords(prompt,tts_max_len);
723+
}
724+
695725
if(ttsdebugmode==1 && !tts_is_quiet)
696726
{
697727
printf("\nUsing Speaker ID: %d, Voice: %s", speaker_seed, voiceused.c_str());

0 commit comments

Comments
 (0)