Updated audio to allow for download of single audio file with all actions in it

This commit is contained in:
ebolam
2023-09-27 14:37:51 -04:00
parent 67af0ce102
commit 256da85b41
3 changed files with 56 additions and 5 deletions

View File

@@ -7929,6 +7929,52 @@ def UI_2_audio():
mimetype="audio/ogg")
show_error_notification("Error generating audio chunk", f"Something happened. Maybe check the log?")
#==================================================================#
# Download complete audio file
#==================================================================#
@app.route("/audio_full")
@require_allowed_ip
@logger.catch
def UI_2_audio_full():
from pydub import AudioSegment
if args.no_ui:
return redirect('/api/latest')
combined_audio = None
for action_id in range(-1, koboldai_vars.actions.action_count+1):
filename = os.path.join(koboldai_vars.save_paths.generated_audio, f"{action_id}.ogg")
filename_slow = os.path.join(koboldai_vars.save_paths.generated_audio, f"{action_id}_slow.ogg")
complete_filename = os.path.join(koboldai_vars.save_paths.generated_audio, "complete.ogg")
if os.path.exists(filename_slow):
if combined_audio is None:
combined_audio = AudioSegment.from_file(filename_slow, format="ogg")
else:
combined_audio = combined_audio + AudioSegment.from_file(filename_slow, format="ogg")
elif os.path.exists(filename):
if combined_audio is None:
combined_audio = AudioSegment.from_file(filename, format="ogg")
else:
combined_audio = combined_audio + AudioSegment.from_file(filename, format="ogg")
else:
koboldai_vars.actions.gen_audio(action_id)
while not os.path.exists(filename) and time.time()-start_time < 60: #Waiting up to 60 seconds for the file to be generated
time.sleep(0.1)
if os.path.exists(filename):
if combined_audio is None:
combined_audio = AudioSegment.from_file(filename, format="ogg")
else:
combined_audio = combined_audio + AudioSegment.from_file(filename, format="ogg")
else:
show_error_notification("Error generating audio chunk", f"Something happened. Maybe check the log?")
file_handle = combined_audio.export(complete_filename, format="ogg")
return send_file(
complete_filename,
as_attachment=True,
download_name = koboldai_vars.story_name,
mimetype="audio/ogg")
#==================================================================#
# Download of the image for an action

View File

@@ -2058,7 +2058,6 @@ class KoboldStoryRegister(object):
if action_id is None:
action_id = self.action_count
logger.info("Got request to generate audio for {}".format(action_id))
if self.tts_model is None:
language = 'en'
model_id = 'v3_en'
@@ -2072,15 +2071,14 @@ class KoboldStoryRegister(object):
filename = os.path.join(self._koboldai_vars.save_paths.generated_audio, f"{action_id}.ogg")
filename_slow = os.path.join(self._koboldai_vars.save_paths.generated_audio, f"{action_id}_slow.ogg")
logger.info("Got request to generate audio for {}".format(filename))
if overwrite or not os.path.exists(filename):
if action_id == -1:
self.make_audio_queue.put((self._koboldai_vars.prompt, filename))
else:
self.make_audio_queue.put((self.actions[action_id]['Selected Text'], filename))
if self.make_audio_thread_slow is None or not self.make_audio_thread_slow.is_alive():
self.make_audio_thread_slow = threading.Thread(target=self.create_wave_slow, args=(self.make_audio_queue_slow, ))
self.make_audio_thread_slow.start()
if self.make_audio_thread is None or not self.make_audio_thread.is_alive():
self.make_audio_thread = threading.Thread(target=self.create_wave, args=(self.make_audio_queue, ))
self.make_audio_thread.start()
if overwrite or not os.path.exists(filename_slow):
if action_id == -1:

View File

@@ -3790,6 +3790,13 @@ function stop_tts() {
}
}
function download_tts() {
var link = document.createElement("a");
link.download = document.getElementsByClassName("var_sync_story_story_name ")[0].text+".ogg";
link.href = "/audio_full";
link.click();
}
function finished_tts() {
next_action = parseInt(document.getElementById("reader").getAttribute("action_id"))+1;
action_count = parseInt(document.getElementById("action_count").textContent);