@@ -7448,6 +7448,10 @@ Current version indicated by LITEVER below.
74487448 if (userinput != null && userinput!="") {
74497449 localsettings.saved_oai_tts_key = userinput.trim();
74507450 }
7451+ else
7452+ {
7453+ localsettings.saved_oai_tts_key = "";
7454+ }
74517455 },false,false,true);
74527456 }
74537457 function set_oai_tts_url()
@@ -15906,11 +15910,16 @@ Current version indicated by LITEVER below.
1590615910 }
1590715911 userinput = userinput.trim();
1590815912 if (userinput != null && userinput!="" && ssval > 0) {
15909- tts_speak(userinput,downloadtts,embedtts);
15913+ tts_speak(userinput,downloadtts,embedtts,false );
1591015914 }
1591115915 },true);
1591215916 }
1591315917
15918+ function test_tts()
15919+ {
15920+ tts_speak("Hello there, this is a test.",false,false,true);
15921+ }
15922+
1591415923 function toggle_tts_mode()
1591515924 {
1591615925 document.getElementById("xtts_container").classList.add("hidden");
@@ -16072,7 +16081,7 @@ Current version indicated by LITEVER below.
1607216081 reader.readAsDataURL(file);
1607316082 }
1607416083
16075- function tts_speak(text, do_download=false, do_embed_tts=false)
16084+ function tts_speak(text, do_download=false, do_embed_tts=false, is_test=false )
1607616085 {
1607716086 if(!text || text=="" || text.trim()=="")
1607816087 {
@@ -16081,7 +16090,20 @@ Current version indicated by LITEVER below.
1608116090 let ssval = localsettings.tts_mode;
1608216091 let ssrate = localsettings.tts_speed;
1608316092 let vcjson = localsettings.kcpp_tts_json;
16084- if(localsettings.narrate_only_dialog)
16093+ let narrateonlydialog = localsettings.narrate_only_dialog;
16094+ let pickedwebvoice = localsettings.wb_tts_choice;
16095+
16096+ if(is_test)
16097+ {
16098+ //testing from settings page
16099+ ssval = document.getElementById("ttsselect").value;
16100+ ssrate = document.getElementById("tts_speed").value;
16101+ vcjson = kcpp_tts_json;
16102+ narrateonlydialog = false;
16103+ pickedwebvoice = document.getElementById("wb_tts_choice").value;
16104+ }
16105+
16106+ if(narrateonlydialog)
1608516107 {
1608616108 // Remove text within asterisks and the asterisks, then trim
1608716109 text = text.replace(italics_regex,"").trim();
@@ -16434,14 +16456,13 @@ Current version indicated by LITEVER below.
1643416456 else if(ssval==WEBBROWSER_TTS_ID)
1643516457 {
1643616458 let voicelist = window.speechSynthesis.getVoices();
16437- let pickedvoice = localsettings.wb_tts_choice;
16438- if(pickedvoice > voicelist.length)
16459+ if(pickedwebvoice > voicelist.length)
1643916460 {
16440- pickedvoice = 0;
16461+ pickedwebvoice = 0;
1644116462 }
1644216463 if ('speechSynthesis' in window) {
1644316464 let utterance = new window.SpeechSynthesisUtterance(text);
16444- utterance.voice = voicelist[pickedvoice ];
16465+ utterance.voice = voicelist[pickedwebvoice ];
1644516466 utterance.rate = ssrate;
1644616467 window.speechSynthesis.speak(utterance);
1644716468 utterance.onend = function(event) {
@@ -16679,7 +16700,7 @@ Current version indicated by LITEVER below.
1667916700 {
1668016701 if(localsettings.narrate_targets==2)
1668116702 {
16682- tts_speak(newgen,false,localsettings.embed_narrations);
16703+ tts_speak(newgen,false,localsettings.embed_narrations,false );
1668316704 }
1668416705 }
1668516706
@@ -17774,7 +17795,39 @@ Current version indicated by LITEVER below.
1777417795 }
1777517796 else //auto role
1777617797 {
17777- let mhistory = repack_instruct_history(mainoaibody);
17798+ let mhistory = null;
17799+ if (typeof mainoaibody === 'string' || mainoaibody instanceof String)
17800+ {
17801+ mhistory = repack_instruct_history(mainoaibody);
17802+ }
17803+ else
17804+ {
17805+ //it's an object/array, so repack the text turn
17806+ let t1 = mainoaibody[0].text;
17807+ mhistory = repack_instruct_history(t1);
17808+
17809+ //many backends REFUSE to allow the assistant to go first. If the first turn belongs to assistant, we turn it into user
17810+ if(mhistory.length>0 && !mhistory[0].myturn)
17811+ {
17812+ mhistory[0].myturn = true;
17813+ }
17814+ //if both first and second turns are from user, merge them into one turn
17815+ if(mhistory.length>1 && mhistory[0].myturn && mhistory[1].myturn)
17816+ {
17817+ mhistory[0].msg += "\n"+mhistory[1].msg;
17818+ mhistory.splice(1, 1);
17819+ }
17820+
17821+ if(mhistory.length>0 && mainoaibody.length>1 && mainoaibody[1].type && mainoaibody[1].type!="text")
17822+ {
17823+ mhistory[0].msg = [{type: 'text', text: mhistory[0].msg}];
17824+ for(let i=1;i<mainoaibody.length;++i)
17825+ {
17826+ mhistory[0].msg.push(mainoaibody[i]);
17827+ }
17828+ }
17829+ }
17830+
1777817831 for(let i=0;i<mhistory.length;++i)
1777917832 {
1778017833 oai_payload.messages.push({ "role": (mhistory[i].myturn?"user":"assistant"), "content": mhistory[i].msg });
@@ -19516,7 +19569,7 @@ Current version indicated by LITEVER below.
1951619569
1951719570 if(localsettings.narrate_targets != 0)
1951819571 {
19519- tts_speak(gentxtspeak,false,localsettings.embed_narrations);
19572+ tts_speak(gentxtspeak,false,localsettings.embed_narrations,false );
1952019573 }
1952119574 }
1952219575
@@ -21114,7 +21167,7 @@ Current version indicated by LITEVER below.
2111421167 let box2 = document.getElementById("chat_msg_body");
2111521168 let box3 = document.getElementById("corpostylemain");
2111621169 function isScrolledToBottom(element) {
21117- return element.scrollHeight - element.scrollTop <= element.clientHeight + 250 ;
21170+ return element.scrollHeight - element.scrollTop - element.clientHeight <= 60 ;
2111821171 }
2111921172 if(alwaysscroll || isScrolledToBottom(box1))
2112021173 {
@@ -26010,7 +26063,7 @@ Current version indicated by LITEVER below.
2601026063 <div class="settingitem">
2601126064 <div class="settinglabel">
2601226065 <div class="justifyleft settingsmall" style="width: 100%;">Text To Speech <span class="helpicon">?<span class="helptext">Enable Text-To-Speech to have your story automatically read to you.</span></span></div>
26013- <select title="Text To Speech" class="form-control" id="ttsselect" style="font-size:12px;height:20px;padding:0;margin:0px 0 0;width:calc(100%);" onchange="toggle_tts_mode()">
26066+ <select title="Text To Speech" class="form-control" id="ttsselect" style="font-size:12px;height:20px;padding:0;margin:0px 0 0;width:calc(100% - 35px );" onchange="toggle_tts_mode()">
2601426067 <option value="0">Disabled</option>
2601526068 <option value="1">Browser Inbuilt TTS</option>
2601626069 <option value="2">KoboldCpp TTS API</option>
@@ -26019,6 +26072,7 @@ Current version indicated by LITEVER below.
2601926072 <option value="5">OpenAI-Compat. API Server</option>
2602026073 <option value="6">PollinationsAI TTS API</option>
2602126074 </select>
26075+ <button id="manual_tts" type="button" class="bg_green btn btn-primary" style="height:20px; width:30px; padding:2px 3px;font-size:11px; margin-left: 2px;" onclick="test_tts()">Test</button>
2602226076 <div id="xtts_container" class="settinglabel hidden">
2602326077 <div>
2602426078 <table width="100%"><tr>
0 commit comments