Added streaming API & Current settings endpoint
This commit is contained in:
1 parent
fc857f464c
commit
3bc55a91e5
1 file changed
+84
-10
+84
-10
@@ -81,6 +81,17 @@ else:
|
|||||||
f"[{params['branding']}Startup] \033[91mWarning\033[0m modeldownload.config is missing so please re-download it and save it in the alltalk_tts main folder."
|
f"[{params['branding']}Startup] \033[91mWarning\033[0m modeldownload.config is missing so please re-download it and save it in the alltalk_tts main folder."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
#### Check to see if a finetuned model exists ####
|
||||||
|
##################################################
|
||||||
|
# Set the path to the directory
|
||||||
|
trained_model_directory = this_dir / "models" / "trainedmodel"
|
||||||
|
# Check if the directory "trainedmodel" exists
|
||||||
|
finetuned_model = trained_model_directory.exists()
|
||||||
|
# If the directory exists, check for the existence of the required files
|
||||||
|
if finetuned_model:
|
||||||
|
required_files = ["model.pth", "config.json", "vocab.json"]
|
||||||
|
finetuned_model = all((trained_model_directory / file).exists() for file in required_files)
|
||||||
|
|
||||||
########################
|
########################
|
||||||
#### STARTUP CHECKS ####
|
#### STARTUP CHECKS ####
|
||||||
@@ -98,19 +109,17 @@ except ModuleNotFoundError:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
# DEEPSPEED Import - Check for DeepSpeed and import it if it exists
|
# DEEPSPEED Import - Check for DeepSpeed and import it if it exists
|
||||||
|
deepspeed_available = False
|
||||||
try:
|
try:
|
||||||
import deepspeed
|
import deepspeed
|
||||||
|
deepspeed_available = True
|
||||||
deepspeed_installed = True
|
|
||||||
print(f"[{params['branding']}Startup] DeepSpeed \033[93mDetected\033[0m")
|
|
||||||
print(
|
|
||||||
f"[{params['branding']}Startup] Activate DeepSpeed in {params['branding']} settings"
|
|
||||||
)
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
deepspeed_installed = False
|
pass
|
||||||
print(
|
if deepspeed_available:
|
||||||
f"[{params['branding']}Startup] DeepSpeed \033[93mNot Detected\033[0m. See https://github.com/microsoft/DeepSpeed"
|
print(f"[{params['branding']}Startup] DeepSpeed \033[93mDetected\033[0m")
|
||||||
)
|
print(f"[{params['branding']}Startup] Activate DeepSpeed in {params['branding']} settings")
|
||||||
|
else:
|
||||||
|
print(f"[{params['branding']}Startup] DeepSpeed \033[93mNot Detected\033[0m. See https://github.com/microsoft/DeepSpeed")
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
@@ -729,6 +738,11 @@ async def tts_demo_request(request: Request, text: str = Form(...), voice: str =
|
|||||||
print(f"An error occurred: {e}")
|
print(f"An error occurred: {e}")
|
||||||
return JSONResponse(content={"error": "An error occurred"}, status_code=500)
|
return JSONResponse(content={"error": "An error occurred"}, status_code=500)
|
||||||
|
|
||||||
|
|
||||||
|
#####################
|
||||||
|
#### Audio feeds ####
|
||||||
|
#####################
|
||||||
|
|
||||||
# Gives web access to the output files
|
# Gives web access to the output files
|
||||||
@app.get("/audio/{filename}")
|
@app.get("/audio/{filename}")
|
||||||
async def get_audio(filename: str):
|
async def get_audio(filename: str):
|
||||||
@@ -808,6 +822,34 @@ import numpy as np
|
|||||||
import soundfile as sf
|
import soundfile as sf
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
##############################
|
||||||
|
#### Streaming Generation ####
|
||||||
|
##############################
|
||||||
|
|
||||||
|
@app.get("/api/tts-generate-streaming", response_class=StreamingResponse)
|
||||||
|
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)
|
||||||
|
return StreamingResponse(stream, media_type="audio/wav")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
return JSONResponse(content={"error": "An error occurred"}, status_code=500)
|
||||||
|
|
||||||
|
@app.post("/api/tts-generate-streaming", response_class=JSONResponse)
|
||||||
|
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)
|
||||||
|
return JSONResponse(content={"output_file_path": str(output_file)}, status_code=200)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
return JSONResponse(content={"error": "An error occurred"}, status_code=500)
|
||||||
|
|
||||||
|
##############################
|
||||||
|
#### Standard Generation ####
|
||||||
|
##############################
|
||||||
|
|
||||||
# Check for PortAudio library on Linux
|
# Check for PortAudio library on Linux
|
||||||
try:
|
try:
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
@@ -1053,6 +1095,38 @@ async def tts_generate(
|
|||||||
return JSONResponse(content={"status": "generate-failure", "error": "An error occurred"}, status_code=500)
|
return JSONResponse(content={"status": "generate-failure", "error": "An error occurred"}, status_code=500)
|
||||||
|
|
||||||
|
|
||||||
|
##########################
|
||||||
|
#### Current Settings ####
|
||||||
|
##########################
|
||||||
|
# Define the available models
|
||||||
|
models_available = [
|
||||||
|
{"name": "Coqui", "model_name": "API TTS"},
|
||||||
|
{"name": "Coqui", "model_name": "API Local"},
|
||||||
|
{"name": "Coqui", "model_name": "XTTSv2 Local"}
|
||||||
|
]
|
||||||
|
|
||||||
|
@app.get('/api/currentsettings')
|
||||||
|
def get_current_settings():
|
||||||
|
# Determine the current model loaded
|
||||||
|
if params["tts_method_api_tts"]:
|
||||||
|
current_model_loaded = "API TTS"
|
||||||
|
elif params["tts_method_api_local"]:
|
||||||
|
current_model_loaded = "API Local"
|
||||||
|
elif params["tts_method_xtts_local"]:
|
||||||
|
current_model_loaded = "XTTSv2 Local"
|
||||||
|
else:
|
||||||
|
current_model_loaded = None # or a default value if no method is active
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
"models_available": models_available,
|
||||||
|
"current_model_loaded": current_model_loaded,
|
||||||
|
"deepspeed_available": deepspeed_available,
|
||||||
|
"deepspeed_status": params["deepspeed_activate"],
|
||||||
|
"low_vram_status": params["low_vram"],
|
||||||
|
"finetuned_model": finetuned_model
|
||||||
|
}
|
||||||
|
return settings # Automatically converted to JSON by Fas
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
#### Word Add-in Sharing ####
|
#### Word Add-in Sharing ####
|
||||||
#############################
|
#############################
|
||||||
|
|||||||
Reference in new issue
Block a user