mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-07-09 17:08:33 +00:00
option to save tts as mp3, currently slightly bugged
This commit is contained in:
parent
2c64520ba6
commit
1b36e7f606
4 changed files with 29 additions and 6 deletions
|
|
@ -307,6 +307,11 @@ select{
|
|||
<input title="TTS Instruction" id="tts_instruction" placeholder="e.g. angry shouting loud male">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px">
|
||||
<label>Save as MP3</label>
|
||||
<input title="Save as MP3" id="tts_use_mp3" type="checkbox" style="max-width:30px">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:14px">
|
||||
<label>API Base URL (optional)</label>
|
||||
<input id="tts_baseUrl" placeholder="http://localhost:5001">
|
||||
|
|
@ -445,7 +450,8 @@ async function generateTTS(){
|
|||
|
||||
const payload = {
|
||||
input: document.getElementById("tts_input").value,
|
||||
voice: document.getElementById("tts_voice").value
|
||||
voice: document.getElementById("tts_voice").value,
|
||||
use_mp3: document.getElementById("tts_use_mp3").checked
|
||||
};
|
||||
|
||||
const instruction = document.getElementById("tts_instruction").value;
|
||||
|
|
@ -495,6 +501,7 @@ async function generateTTS(){
|
|||
function clearTTS(){
|
||||
document.getElementById("tts_input").value="";
|
||||
document.getElementById("tts_instruction").value="";
|
||||
document.getElementById("tts_use_mp3").checked=false;
|
||||
}
|
||||
|
||||
//end of tts part
|
||||
|
|
@ -935,4 +942,4 @@ fetchStats();
|
|||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
1
expose.h
1
expose.h
|
|
@ -320,6 +320,7 @@ struct tts_generation_inputs
|
|||
const char * custom_speaker_data = "";
|
||||
const char * reference_audio = "";
|
||||
const char * speaker_instruction = "";
|
||||
const bool use_mp3 = false;
|
||||
};
|
||||
struct tts_generation_outputs
|
||||
{
|
||||
|
|
|
|||
|
|
@ -498,7 +498,8 @@ class tts_generation_inputs(ctypes.Structure):
|
|||
("custom_speaker_text", ctypes.c_char_p),
|
||||
("custom_speaker_data", ctypes.c_char_p),
|
||||
("reference_audio", ctypes.c_char_p),
|
||||
("speaker_instruction", ctypes.c_char_p)]
|
||||
("speaker_instruction", ctypes.c_char_p),
|
||||
("use_mp3", ctypes.c_bool)]
|
||||
|
||||
class tts_generation_outputs(ctypes.Structure):
|
||||
_fields_ = [("status", ctypes.c_int),
|
||||
|
|
@ -2999,6 +3000,7 @@ def tts_generate(genparams):
|
|||
if not genparams.get("instruction", ""):
|
||||
prompt, ttsinstruction = tts_extract_instruction(prompt)
|
||||
inputs.speaker_instruction = ttsinstruction.encode("UTF-8")
|
||||
inputs.use_mp3 = genparams.get("use_mp3", False)
|
||||
inputs.prompt = prompt.encode("UTF-8")
|
||||
inputs.speaker_seed = voice
|
||||
aseed = -1
|
||||
|
|
|
|||
|
|
@ -492,6 +492,19 @@ static int code_terminate_id = 151670;
|
|||
static int nthreads = 4;
|
||||
static int tts_max_len = 4096;
|
||||
|
||||
static std::string save_tts_audio_base64(const std::vector<float> & audio, int sample_rate, bool use_mp3)
|
||||
{
|
||||
if (!use_mp3) {
|
||||
return save_wav16_base64(audio, sample_rate);
|
||||
}
|
||||
|
||||
std::vector<float> stereo_audio;
|
||||
stereo_audio.reserve(audio.size() * 2);
|
||||
stereo_audio.insert(stereo_audio.end(), audio.begin(), audio.end());
|
||||
stereo_audio.insert(stereo_audio.end(), audio.begin(), audio.end());
|
||||
return save_stereo_mp3_base64(stereo_audio, (int) audio.size(), sample_rate);
|
||||
}
|
||||
|
||||
//ttscpp specific
|
||||
static bool is_ttscpp_file = false;
|
||||
static generation_configuration * ttscpp_config = nullptr;
|
||||
|
|
@ -718,7 +731,7 @@ static tts_generation_outputs ttstype_generate_ttscpp(const tts_generation_input
|
|||
printf("\nTTS Generated audio in %.2fs.\n",ttstime);
|
||||
std::vector<float> wavdat = std::vector(response_data.data, response_data.data + response_data.n_outputs);
|
||||
//audio_post_clean(wavdat);
|
||||
last_generated_audio = save_wav16_base64(wavdat, ttscpp_runner->sampling_rate);
|
||||
last_generated_audio = save_tts_audio_base64(wavdat, ttscpp_runner->sampling_rate, inputs.use_mp3);
|
||||
output.data = last_generated_audio.c_str();
|
||||
output.status = 1;
|
||||
last_generation_settings_audio_seed = 0;
|
||||
|
|
@ -1131,7 +1144,7 @@ static tts_generation_outputs ttstype_generate_outetts(const tts_generation_inpu
|
|||
return output;
|
||||
}
|
||||
|
||||
last_generated_audio = save_wav16_base64(audio, t_sr);
|
||||
last_generated_audio = save_tts_audio_base64(audio, t_sr, inputs.use_mp3);
|
||||
ttstime = timer_check();
|
||||
|
||||
printf("\nTTS Generated %d audio tokens in %.2fs.\n",(int) codes.size(),ttstime);
|
||||
|
|
@ -1239,7 +1252,7 @@ static tts_generation_outputs ttstype_generate_qwen3tts(const tts_generation_inp
|
|||
|
||||
ttstime = timer_check();
|
||||
printf("\nTTS Generated audio in %.2fs.\n",ttstime);
|
||||
last_generated_audio = save_wav16_base64(result.audio, result.sample_rate);
|
||||
last_generated_audio = save_tts_audio_base64(result.audio, result.sample_rate, inputs.use_mp3);
|
||||
output.data = last_generated_audio.c_str();
|
||||
output.status = 1;
|
||||
last_generation_settings_audio_seed = inputs.audio_seed;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue