diff --git a/script.py b/script.py
index 677dd2d..e569ff8 100644
--- a/script.py
+++ b/script.py
@@ -489,12 +489,14 @@ def voice_preview(string):
output_file = Path(params["output_folder_wav"]) / "voice_preview.wav"
# Generate the audio
language_code = languages.get(params["language"])
+ temperature = params["local_temperature"]
+ repetition_penalty = params["local_repetition_penalty"]
# Convert the WindowsPath object to a string before using it in JSON payload
output_file_str = output_file.as_posix()
# Lock before making the generate request
with process_lock:
generate_response = send_generate_request(
- string, params["voice"], language_code, output_file_str
+ string, params["voice"], language_code, temperature, repetition_penalty, output_file_str
)
# Check if lock is already acquired
if process_lock.locked():
@@ -573,6 +575,8 @@ def output_modifier(string, state):
return
string = cleaned_string
language_code = languages.get(params["language"])
+ temperature = params["local_temperature"]
+ repetition_penalty = params["local_repetition_penalty"]
# Create a list to store generated audio paths
audio_files = []
if process_lock.acquire(blocking=False):
@@ -635,7 +639,7 @@ def output_modifier(string, state):
output_file_str = output_file.as_posix()
output_file = get_output_filename(state)
generate_response = send_generate_request(
- cleaned_part, params["voice"], language_code, output_file_str
+ cleaned_part, params["voice"], language_code, temperature, repetition_penalty, output_file_str
)
audio_path = generate_response.get("data", {}).get("audio_path")
final_output_file = audio_path
@@ -684,12 +688,14 @@ def get_output_filename(state):
###############################################
#### SEND GENERATION REQUEST TO TTS ENGINE ####
###############################################
-def send_generate_request(text, voice, language, output_file):
+def send_generate_request(text, voice, language, temperature, repetition_penalty, output_file):
url = f"{base_url}/api/generate"
payload = {
"text": text,
"voice": voice,
"language": language,
+ "temperature": temperature,
+ "repetition_penalty": repetition_penalty,
"output_file": output_file,
}
headers = {"Content-Type": "application/json"}
@@ -737,11 +743,13 @@ def input_modifier(string, state):
def ui():
with gr.Accordion(params["branding"] + " TTS (XTTSv2)"):
+ # Activate alltalk_tts, Enable autoplay, Show text
with gr.Row():
activate = gr.Checkbox(value=params['activate'], label='Enable TTS')
autoplay = gr.Checkbox(value=params['autoplay'], label='Autoplay TTS')
show_text = gr.Checkbox(value=params['show_text'], label='Show Text')
-
+
+ # Low vram enable, Deepspeed enable, Remove trailing dots
with gr.Row():
low_vram = gr.Checkbox(value=params['low_vram'], label='Enable Low VRAM Mode')
low_vram_play = gr.HTML(visible=False)
@@ -749,6 +757,7 @@ def ui():
deepspeed_checkbox_play = gr.HTML(visible=False)
remove_trailing_dots = gr.Checkbox(value=params['remove_trailing_dots'], label='Remove trailing "."')
+ # TTS method, Character voice selection
with gr.Row():
model_loader_choices=["API TTS", "API Local", "XTTSv2 Local"]
if finetuned_model:
@@ -769,17 +778,19 @@ def ui():
voice = gr.Dropdown(available_voices, label="Character Voice", value=default_voice, allow_custom_value=True, )
create_refresh_button(voice, lambda: None, lambda: {"choices": get_available_voices(), "value": params["voice"],}, "refresh-button",)
+ # Language, Narrator voice
with gr.Row():
language = gr.Dropdown(languages.keys(), label="Language", value=params["language"])
with gr.Row():
narrator_voice_gr = gr.Dropdown(get_available_voices(), label="Narrator Voice", allow_custom_value=True, value=params["narrator_voice"])
create_refresh_button(narrator_voice_gr, lambda: None, lambda: {"choices": get_available_voices(), "value": params["narrator_voice"],}, "refresh-button")
- # Temperature and Repetition Penalty (Not yet parsed to api/implemented)
- # with gr.Row():
- # local_temperature_gr = gr.Slider(minimum=0, maximum=1, step=0.05, label="Temperature", value=params["local_temperature"])
- # local_repetition_penalty_gr = gr.Slider(minimum=0, maximum=20, step=0.5, label="Repetition Penalty", value=params["local_repetition_penalty"])
+ # Temperature, Repetition Penalty
+ with gr.Row():
+ local_temperature_gr = gr.Slider(minimum=0.05, maximum=1, step=0.05, label="Temperature", value=params["local_temperature"])
+ local_repetition_penalty_gr = gr.Slider(minimum=0.5, maximum=20, step=0.5, label="Repetition Penalty", value=params["local_repetition_penalty"])
+ # Narrator enable, Non quoted text, Explanation text
with gr.Row():
with gr.Row():
narrator_enabled_gr = gr.Radio(choices={"Enabled": "true", "Disabled": "false"}, label="Narrator", value="Enabled" if params.get("narrator_enabled") else "Disabled")
@@ -787,6 +798,7 @@ def ui():
explanation_text = gr.HTML(
f"
⚙️ Settings and Documentation Page⚙️
- Low VRAM Mode and Deepspeed take 15 seconds to be enabled or disabled.
- The DeepSpeed checkbox is only visible if DeepSpeed is present.
")
+ # Preview speech
with gr.Row():
preview_text = gr.Text(
show_label=False,
@@ -795,7 +807,7 @@ def ui():
)
preview_play = gr.Button("Preview")
preview_audio = gr.HTML(visible=False)
-
+
with gr.Row():
convert = gr.Button("Permanently replace audios with the message texts")
convert_cancel = gr.Button("Cancel", visible=False)
@@ -864,10 +876,9 @@ def ui():
voice.change(lambda x: params.update({"voice": x}), voice, None)
language.change(lambda x: params.update({"language": x}), language, None)
-
- # TS Settings (Not yet parsed to api/implemented)
- # local_temperature_gr.change(lambda x: params.update({"local_temperature": x}), local_temperature_gr, None)
- # local_repetition_penalty_gr.change(lambda x: params.update({"local_repetition_penalty": x}), local_repetition_penalty_gr, None)
+ # TSS Settings
+ local_temperature_gr.change(lambda x: params.update({"local_temperature": x}), local_temperature_gr, None)
+ local_repetition_penalty_gr.change(lambda x: params.update({"local_repetition_penalty": x}), local_repetition_penalty_gr, None)
# Narrator selection actions
narrator_enabled_gr.change(update_narrator_enabled, narrator_enabled_gr, None)
diff --git a/tts_server.py b/tts_server.py
index 4d2c48b..8d831b7 100644
--- a/tts_server.py
+++ b/tts_server.py
@@ -57,6 +57,10 @@ params = load_config(configfile_path)
# check someone hasnt enabled lowvram on a system thats not cuda enabled
params["low_vram"] = "false" if not torch.cuda.is_available() else params["low_vram"]
+# Load values for temperature and repetition_penalty
+temperature = params["local_temperature"]
+repetition_penalty = params["local_repetition_penalty"]
+
# Define the path to the JSON file
config_file_path = this_dir / "modeldownload.json"
@@ -473,16 +477,16 @@ async def deepspeed(request: Request, new_deepspeed_value: bool):
########################
# TTS VOICE GENERATION METHODS (called from voice_preview and output_modifer)
-async def generate_audio(text, voice, language, output_file, streaming=False):
+async def generate_audio(text, voice, language, temperature, repetition_penalty, output_file, streaming=False):
# Get the async generator from the internal function
- response = generate_audio_internal(text, voice, language, output_file, streaming)
+ response = generate_audio_internal(text, voice, language, temperature, repetition_penalty, output_file, streaming)
# If streaming, then return the generator as-is, otherwise just exhaust it and return
if streaming:
return response
async for _ in response:
pass
-async def generate_audio_internal(text, voice, language, output_file, streaming):
+async def generate_audio_internal(text, voice, language, temperature, repetition_penalty, output_file, streaming):
global model
if params["low_vram"] and device == "cpu":
await switch_device()
@@ -504,9 +508,9 @@ async def generate_audio_internal(text, voice, language, output_file, streaming)
"language": language,
"gpt_cond_latent": gpt_cond_latent,
"speaker_embedding": speaker_embedding,
- "temperature": float(params["local_temperature"]),
+ "temperature": float(temperature),
"length_penalty": float(model.config.length_penalty),
- "repetition_penalty": float(params["local_repetition_penalty"]),
+ "repetition_penalty": float(repetition_penalty),
"top_k": int(model.config.top_k),
"top_p": float(model.config.top_p),
"enable_text_splitting": True
@@ -560,9 +564,9 @@ async def generate_audio_internal(text, voice, language, output_file, streaming)
file_path=output_file,
speaker_wav=[f"{this_dir}/voices/{voice}"],
language=language,
- temperature=float(params["local_temperature"]),
+ temperature=temperature,
length_penalty=model.config.length_penalty,
- repetition_penalty=float(params["local_repetition_penalty"]),
+ repetition_penalty=repetition_penalty,
top_k=model.config.top_k,
top_p=model.config.top_p,
)
@@ -602,10 +606,12 @@ async def generate(request: Request):
text = data["text"]
voice = data["voice"]
language = data["language"]
+ temperature = data["temperature"]
+ repetition_penalty = data["repetition_penalty"]
output_file = data["output_file"]
streaming = False
# Generation logic
- response = await generate_audio(text, voice, language, output_file, streaming)
+ response = await generate_audio(text, voice, language, temperature, repetition_penalty, output_file, streaming)
if streaming:
return StreamingResponse(response, media_type="audio/wav")
return JSONResponse(
@@ -722,7 +728,7 @@ async def update_settings(
async def tts_demo_request_streaming(text: str, voice: str, language: str, output_file: str):
try:
output_file_path = this_dir / "outputs" / output_file
- stream = await generate_audio(text, voice, language, output_file_path, streaming=True)
+ stream = await generate_audio(text, voice, language, temperature, repetition_penalty, output_file_path, streaming=True)
return StreamingResponse(stream, media_type="audio/wav")
except Exception as e:
print(f"An error occurred: {e}")
@@ -732,7 +738,7 @@ async def tts_demo_request_streaming(text: str, voice: str, language: str, outpu
async def tts_demo_request(request: Request, text: str = Form(...), voice: str = Form(...), language: str = Form(...), output_file: str = Form(...)):
try:
output_file_path = this_dir / "outputs" / output_file
- await generate_audio(text, voice, language, output_file_path, streaming=False)
+ await generate_audio(text, voice, language, temperature, repetition_penalty, output_file_path, streaming=False)
return JSONResponse(content={"output_file_path": str(output_file)}, status_code=200)
except Exception as e:
print(f"An error occurred: {e}")
@@ -794,7 +800,7 @@ async def preview_voice(request: Request, voice: str = Form(...)):
# Generate the audio
output_file_path = this_dir / "outputs" / f"{output_file_name}.wav"
- await generate_audio(text, voice, language, output_file_path, streaming=False)
+ await generate_audio(text, voice, language, temperature, repetition_penalty, output_file_path, streaming=False)
# Generate the URL
output_file_url = f'http://{params["ip_address"]}:{params["port_number"]}/audio/{output_file_name}.wav'
@@ -831,7 +837,7 @@ import hashlib
async def tts_generate_streaming(text: str, voice: str, language: str, output_file: str):
try:
output_file_path = this_dir / "outputs" / output_file
- stream = await generate_audio(text, voice, language, output_file_path, streaming=True)
+ stream = await generate_audio(text, voice, language, temperature, repetition_penalty, output_file_path, streaming=True)
return StreamingResponse(stream, media_type="audio/wav")
except Exception as e:
print(f"An error occurred: {e}")
@@ -841,7 +847,7 @@ async def tts_generate_streaming(text: str, voice: str, language: str, output_fi
async def tts_generate_streaming(request: Request, text: str = Form(...), voice: str = Form(...), language: str = Form(...), output_file: str = Form(...)):
try:
output_file_path = this_dir / "outputs" / output_file
- await generate_audio(text, voice, language, output_file_path, streaming=False)
+ await generate_audio(text, voice, language, temperature, repetition_penalty, output_file_path, streaming=False)
return JSONResponse(content={"output_file_path": str(output_file)}, status_code=200)
except Exception as e:
print(f"An error occurred: {e}")
@@ -1054,7 +1060,7 @@ async def tts_generate(
cleaned_part = re.sub(r'\n+', ' ', cleaned_part)
output_file = this_dir / "outputs" / f"{output_file_name}_{uuid.uuid4()}_{int(time.time())}.wav"
output_file_str = output_file.as_posix()
- response = await generate_audio(cleaned_part, voice_to_use, language, output_file_str, streaming)
+ response = await generate_audio(cleaned_part, voice_to_use, language,temperature, repetition_penalty, output_file_str, streaming)
audio_path = output_file_str
audio_files_all_paragraphs.append(audio_path)
# Combine audio files across paragraphs
@@ -1091,7 +1097,7 @@ async def tts_generate(
cleaned_string = re.sub(r'\n+', ' ', cleaned_string)
else:
cleaned_string = text_input
- response = await generate_audio(cleaned_string, character_voice_gen, language, output_file_path, streaming)
+ response = await generate_audio(cleaned_string, character_voice_gen, language, temperature, repetition_penalty, output_file_path, streaming)
if sounddevice_installed == False or streaming == True:
autoplay = False
if autoplay: