Populate settings with wav voices

This commit is contained in:
erew123 authored and GitHub committed 2023-12-10 09:49:07 +00:00
1 parent 3264dfecde
commit 9927b51622
1 file changed
+11 -3
+11 -3
View File
@@ -459,6 +459,14 @@ async def generate(request: Request):
return JSONResponse(content={"status": "error", "message": str(e)}) return JSONResponse(content={"status": "error", "message": str(e)})
###################################################
#### POPULATE FILES LIST FROM VOICES DIRECTORY ####
###################################################
# List files in the "voices" directory
def list_files(directory):
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f)) and f.endswith('.wav')]
return files
############################# #############################
#### JSON CONFIG UPDATER #### #### JSON CONFIG UPDATER ####
############################# #############################
@@ -466,7 +474,6 @@ async def generate(request: Request):
# Create an instance of Jinja2Templates for rendering HTML templates # Create an instance of Jinja2Templates for rendering HTML templates
templates = Jinja2Templates(directory=this_dir / "templates") templates = Jinja2Templates(directory=this_dir / "templates")
# Create a dependency to get the current JSON data # Create a dependency to get the current JSON data
def get_json_data(): def get_json_data():
with open(this_dir / "config.json", "r") as json_file: with open(this_dir / "config.json", "r") as json_file:
@@ -477,17 +484,18 @@ def get_json_data():
# Define an endpoint function # Define an endpoint function
@app.get("/settings") @app.get("/settings")
async def get_settings(request: Request): async def get_settings(request: Request):
# Render the template with the current JSON data wav_files = list_files(this_dir / "voices")
# Render the template with the current JSON data and list of WAV files
return templates.TemplateResponse( return templates.TemplateResponse(
"generate_form.html", "generate_form.html",
{ {
"request": request, "request": request,
"data": get_json_data(), "data": get_json_data(),
"modeldownload_model_path": modeldownload_model_path, "modeldownload_model_path": modeldownload_model_path,
"wav_files": wav_files,
}, },
) )
@app.post("/update-settings") @app.post("/update-settings")
async def update_settings( async def update_settings(
request: Request, request: Request,