mirror of
https://github.com/KoboldAI/KoboldAI-Client.git
synced 2025-06-05 21:59:24 +02:00
Merge branch 'UI2' of https://github.com/ebolam/KoboldAI into ui2-story-review
This commit is contained in:
@@ -1269,14 +1269,6 @@ def loadsettings():
|
|||||||
with open("settings/" + getmodelname().replace('/', '_') + ".v2_settings", "r") as file:
|
with open("settings/" + getmodelname().replace('/', '_') + ".v2_settings", "r") as file:
|
||||||
getattr(koboldai_vars, "_model_settings").from_json(file.read())
|
getattr(koboldai_vars, "_model_settings").from_json(file.read())
|
||||||
|
|
||||||
file.close()
|
|
||||||
if(path.exists(get_config_filename())):
|
|
||||||
# Read file contents into JSON object
|
|
||||||
file = open(get_config_filename(), "r")
|
|
||||||
js = json.load(file)
|
|
||||||
|
|
||||||
processsettings(js)
|
|
||||||
file.close()
|
|
||||||
|
|
||||||
def processsettings(js):
|
def processsettings(js):
|
||||||
# Copy file contents to vars
|
# Copy file contents to vars
|
||||||
|
@@ -18,6 +18,9 @@ serverstarted = False
|
|||||||
queue = None
|
queue = None
|
||||||
multi_story = False
|
multi_story = False
|
||||||
|
|
||||||
|
if importlib.util.find_spec("tortoise") is not None:
|
||||||
|
from tortoise import api
|
||||||
|
from tortoise.utils.audio import load_voices
|
||||||
|
|
||||||
def clean_var_for_emit(value):
|
def clean_var_for_emit(value):
|
||||||
if isinstance(value, KoboldStoryRegister) or isinstance(value, KoboldWorldInfo):
|
if isinstance(value, KoboldStoryRegister) or isinstance(value, KoboldWorldInfo):
|
||||||
@@ -932,7 +935,8 @@ class story_settings(settings):
|
|||||||
if self.story_id == j["story_id"]:
|
if self.story_id == j["story_id"]:
|
||||||
break
|
break
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
raise FileNotFoundError("Malformed save file: Missing story.json")
|
logger.error(f"Malformed save file: Missing story.json in {self.save_paths.base}. Populating it with new data.")
|
||||||
|
break
|
||||||
|
|
||||||
disambiguator += 1
|
disambiguator += 1
|
||||||
self.save_paths.base = os.path.join("stories", save_name + (f" ({disambiguator})" if disambiguator else ""))
|
self.save_paths.base = os.path.join("stories", save_name + (f" ({disambiguator})" if disambiguator else ""))
|
||||||
@@ -950,8 +954,11 @@ class story_settings(settings):
|
|||||||
logger.info("Migrating v2 save")
|
logger.info("Migrating v2 save")
|
||||||
with open(v2_path, "r") as file:
|
with open(v2_path, "r") as file:
|
||||||
v2j = json.load(file)
|
v2j = json.load(file)
|
||||||
assert v2j["story_id"] == self.story_id
|
|
||||||
shutil.move(v2_path, os.path.join(self.save_paths.base, ".v2_old.json"))
|
if v2j["story_id"] == self.story_id:
|
||||||
|
shutil.move(v2_path, os.path.join(self.save_paths.base, ".v2_old.json"))
|
||||||
|
else:
|
||||||
|
logger.warning(f"Story mismatch in v2 migration. Existing file had story id {v2j['story_id']} but we have {self.story_id}")
|
||||||
|
|
||||||
with open(self.save_paths.story, "w") as file:
|
with open(self.save_paths.story, "w") as file:
|
||||||
file.write(self.to_json())
|
file.write(self.to_json())
|
||||||
@@ -2001,16 +2008,16 @@ class KoboldStoryRegister(object):
|
|||||||
def create_wave_slow(self, make_audio_queue_slow):
|
def create_wave_slow(self, make_audio_queue_slow):
|
||||||
import pydub
|
import pydub
|
||||||
sample_rate = 24000
|
sample_rate = 24000
|
||||||
|
speaker = 'train_daws'
|
||||||
if self.tortoise is None:
|
if self.tortoise is None:
|
||||||
try:
|
self.tortoise=api.TextToSpeech()
|
||||||
from tortoise import api
|
|
||||||
self.tortoise=api.TextToSpeech()
|
|
||||||
except:
|
|
||||||
self.tortoise = False
|
|
||||||
|
|
||||||
if self.tortoise is not False:
|
if importlib.util.find_spec("tortoise") is not None:
|
||||||
|
voice_samples, conditioning_latents = load_voices([speaker])
|
||||||
while not make_audio_queue_slow.empty():
|
while not make_audio_queue_slow.empty():
|
||||||
|
start_time = time.time()
|
||||||
(text, filename) = make_audio_queue_slow.get()
|
(text, filename) = make_audio_queue_slow.get()
|
||||||
|
text_length = len(text)
|
||||||
logger.info("Creating audio for {}".format(os.path.basename(filename)))
|
logger.info("Creating audio for {}".format(os.path.basename(filename)))
|
||||||
if text.strip() == "":
|
if text.strip() == "":
|
||||||
shutil.copy("data/empty_audio.ogg", filename)
|
shutil.copy("data/empty_audio.ogg", filename)
|
||||||
@@ -2021,13 +2028,14 @@ class KoboldStoryRegister(object):
|
|||||||
text = [text]
|
text = [text]
|
||||||
output = None
|
output = None
|
||||||
for process_text in text:
|
for process_text in text:
|
||||||
audio = self.tortoise.tts_with_preset(process_text, preset='fast').numpy()
|
audio = self.tortoise.tts_with_preset(process_text, preset='ultra_fast', voice_samples=voice_samples, conditioning_latents=conditioning_latents).numpy()
|
||||||
channels = 2 if (audio.ndim == 2 and audio.shape[1] == 2) else 1
|
channels = 2 if (audio.ndim == 2 and audio.shape[1] == 2) else 1
|
||||||
if output is None:
|
if output is None:
|
||||||
output = pydub.AudioSegment(np.int16(audio * 2 ** 15).tobytes(), frame_rate=sample_rate, sample_width=2, channels=channels)
|
output = pydub.AudioSegment(np.int16(audio * 2 ** 15).tobytes(), frame_rate=sample_rate, sample_width=2, channels=channels)
|
||||||
else:
|
else:
|
||||||
output = output + pydub.AudioSegment(np.int16(audio * 2 ** 15).tobytes(), frame_rate=sample_rate, sample_width=2, channels=channels)
|
output = output + pydub.AudioSegment(np.int16(audio * 2 ** 15).tobytes(), frame_rate=sample_rate, sample_width=2, channels=channels)
|
||||||
output.export(filename, format="ogg", bitrate="16k")
|
output.export(filename, format="ogg", bitrate="16k")
|
||||||
|
logger.info("Slow audio took {} for {} characters".format(time.time()-start_time, text_length))
|
||||||
|
|
||||||
|
|
||||||
def gen_all_audio(self, overwrite=False):
|
def gen_all_audio(self, overwrite=False):
|
||||||
|
Reference in New Issue
Block a user