From ff572702867a524095d2a4a10a176df8ca3fab90 Mon Sep 17 00:00:00 2001
From: erew123 <35898566+erew123@users.noreply.github.com>
Date: Fri, 29 Dec 2023 09:53:02 +0000
Subject: [PATCH 1/9] Update README.md
---
README.md | 81 +++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 58 insertions(+), 23 deletions(-)
diff --git a/README.md b/README.md
index 3e728f2..28fa6fe 100644
--- a/README.md
+++ b/README.md
@@ -499,6 +499,64 @@ Deepspeed and other such things can be installed. Please read the relevant instr
### π Overview
The Text-to-Speech (TTS) Generation API allows you to generate speech from text input using various configuration options. This API supports both character and narrator voices, providing flexibility for creating dynamic and engaging audio content.
+#### π Ready Endpoint
+Check if the Text-to-Speech (TTS) service is ready to accept requests.
+
+- URL: `http://127.0.0.1:7851/api/ready`
- Method: `GET`
- Response: `Ready`
+
+ `curl -X GET "http://127.0.0.1:7851/api/ready"`
+
+#### π Voices List Endpoint
+Retrieve a list of available voices for generating speech.
+
+- URL: `http://127.0.0.1:7851/api/voices`
- Method: `GET`
+
+ `curl -X GET "http://127.0.0.1:7851/api/voices"`
+
+ JSON return: `{"voices": ["voice1.wav", "voice2.wav", "voice3.wav"]}`
+
+#### π Preview Voice Endpoint
+Generate a preview of a specified voice with hardcoded settings.
+
+- URL: `http://127.0.0.1:7851/api/previewvoice/`
- Method: `POST`
- Content-Type: `application/x-www-form-urlencoded`
+
+ `curl -X POST "http://127.0.0.1:7851/api/previewvoice/" -F "voice=female_01.wav"`
+
+ Replace `female_01.wav` with the name of the voice sample you want to hear.
+
+ JSON return: `{"status": "generate-success", "output_file_path": "/path/to/outputs/api_preview_voice.wav", "output_file_url": "http://127.0.0.1:7851/audio/api_preview_voice.wav"}`
+
+#### π Switching Model Endpoint
+
+- URL: `http://127.0.0.1:7851/api/reload`
- Method: `POST`
+ `curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20Local"`
+ `curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20TTS"`
+ `curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=XTTSv2%20Local"`
+
+ Switch between the 3 models respectively.
+
+ JSON return `{"status": "model-success"}`
+
+#### π Switch DeepSpeed Endpoint
+
+- URL: `http://127.0.0.1:7851/api/deepspeed`
- Method: `POST`
+ `curl -X POST "http://127.0.0.1:7851/api/deepspeed?new_deepspeed_value=True"`
+
+ Replace True with False to disable DeepSpeed mode.
+
+ JSON return `{"status": "deepspeed-success"}`
+
+#### π Switching Low VRAM Endpoint
+
+- URL: `http://127.0.0.1:7851/api/lowvramsetting`
- Method: `POST`
+ `curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"`
+
+ Replace True with False to disable Low VRAM mode.
+
+ JSON return `{"status": "lowvram-success"}`
+
+### π TTS Generation Endpoint
+
- URL: `http://127.0.0.1:7851/api/tts-generate`
- Method: `POST`
- Content-Type: `application/x-www-form-urlencoded`
@@ -606,29 +664,6 @@ Example JSON TTS Generation Response:
`{"status": "generate-success", "output_file_path": "C:\text-generation-webui\extensions\alltalk_tts\outputs\myoutputfile_1703149973.wav", "output_file_url": "http://127.0.0.1:7851/audio/myoutputfile_1703149973.wav"}`
-π **Switching Model**
-`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20Local"`
-`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=API%20TTS"`
-`curl -X POST "http://127.0.0.1:7851/api/reload?tts_method=XTTSv2%20Local"`
-
-Switch between the 3 models respectively.
-
-JSON return `{"status": "model-success"}`
-
-π **Switch DeepSpeed**
-`curl -X POST "http://127.0.0.1:7851/api/deepspeed?new_deepspeed_value=True"`
-
-Replace True with False to disable DeepSpeed mode.
-
-JSON return `{"status": "deepspeed-success"}`
-
-π **Switching Low VRAM**
-`curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"`
-
-Replace True with False to disable Low VRAM mode.
-
-JSON return `{"status": "lowvram-success"}`
-
### π΄ Future to-do list
- Voice output within the command prompt/terminal (TBD).
- Correct a few spelling mistakes in the documentation.
From 95659d5b7aecfdcb0d9e85ef7df997957a7945bb Mon Sep 17 00:00:00 2001
From: erew123 <35898566+erew123@users.noreply.github.com>
Date: Fri, 29 Dec 2023 09:55:23 +0000
Subject: [PATCH 2/9] Update README.md
---
README.md | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 28fa6fe..984e573 100644
--- a/README.md
+++ b/README.md
@@ -557,9 +557,7 @@ Generate a preview of a specified voice with hardcoded settings.
### π TTS Generation Endpoint
-- URL: `http://127.0.0.1:7851/api/tts-generate`
-- Method: `POST`
-- Content-Type: `application/x-www-form-urlencoded`
+- URL: `http://127.0.0.1:7851/api/tts-generate`
- Method: `POST`
- Content-Type: `application/x-www-form-urlencoded`
### π Example command lines
Standard TTS speech Example (standard text) generating a time-stamped file
From 65e257077c7e44899cf94555bde952423e4e34a5 Mon Sep 17 00:00:00 2001
From: erew123 <35898566+erew123@users.noreply.github.com>
Date: Fri, 29 Dec 2023 09:56:51 +0000
Subject: [PATCH 3/9] 3x new API endpoints
/api/voices/
/api/previewvoice/
/api/ready/
---
tts_server.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/tts_server.py b/tts_server.py
index 61fb07b..6e3db2a 100644
--- a/tts_server.py
+++ b/tts_server.py
@@ -619,6 +619,53 @@ async def get_audio(filename: str):
audio_path = this_dir / "outputs" / filename
return FileResponse(audio_path)
+
+#########################
+#### VOICES LIST API ####
+#########################
+# Define the new endpoint
+@app.get("/api/voices")
+async def get_voices():
+ wav_files = list_files(this_dir / "voices")
+ return {"voices": wav_files}
+
+###########################
+#### PREVIEW VOICE API ####
+###########################
+@app.post("/api/previewvoice/", response_class=JSONResponse)
+async def preview_voice(request: Request, voice: str = Form(...)):
+ try:
+ # Hardcoded settings
+ language = "en"
+ output_file_name = "api_preview_voice"
+
+ # Clean the voice filename for inclusion in the text
+ clean_voice_filename = re.sub(r'\.wav$', '', voice.replace(' ', '_'))
+ clean_voice_filename = re.sub(r'[^a-zA-Z0-9]', ' ', clean_voice_filename)
+
+ # Generate the audio
+ text = f"Hello, this is a preview of voice {clean_voice_filename}."
+
+ # Generate the audio
+ output_file_path = this_dir / "outputs" / f"{output_file_name}.wav"
+ await generate_audio(text, voice, language, output_file_path)
+
+ # Generate the URL
+ output_file_url = f'http://{params["ip_address"]}:{params["port_number"]}/audio/{output_file_name}.wav'
+
+ # Return the response with both local file path and URL
+ return JSONResponse(
+ content={
+ "status": "generate-success",
+ "output_file_path": str(output_file_path),
+ "output_file_url": str(output_file_url),
+ },
+ status_code=200,
+ )
+ except Exception as e:
+ print(f"An error occurred: {e}")
+ return JSONResponse(content={"error": "An error occurred"}, status_code=500)
+
########################
#### GENERATION API ####
########################
@@ -1717,10 +1764,20 @@ template = Template(simple_webpage)
# Render the template with the dynamic values
rendered_html = template.render(params=params)
+###############################
+#### Internal script ready ####
+###############################
@app.get("/ready")
async def ready():
return Response("Ready endpoint")
+############################
+#### External API ready ####
+############################
+@app.get("/api/ready")
+async def ready():
+ return Response("Ready")
+
@app.get("/")
async def read_root():
return HTMLResponse(content=rendered_html, status_code=200)
From e81a88938a2208478ac12347ec1f941651c16eb2 Mon Sep 17 00:00:00 2001
From: erew123 <35898566+erew123@users.noreply.github.com>
Date: Fri, 29 Dec 2023 10:11:01 +0000
Subject: [PATCH 4/9] Completed built-in documentation update
For the new API endpoints
---
tts_server.py | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tts_server.py b/tts_server.py
index 6e3db2a..c92b87d 100644
--- a/tts_server.py
+++ b/tts_server.py
@@ -1720,6 +1720,33 @@ simple_webpage = """
curl -X POST "http://127.0.0.1:7851/api/lowvramsetting?new_low_vram_value=True"
Replace True with False to disable Low VRAM mode.
JSON return {"status": "lowvram-success"}
+Check if the Text-to-Speech (TTS) service is ready to accept requests.
+curl -X GET "http://127.0.0.1:7851/api/ready"
+Retrieve a list of available voices for generating speech.
+curl -X GET "http://127.0.0.1:7851/api/voices"
+JSON return: {"voices": ["voice1.wav", "voice2.wav", "voice3.wav"]}
+Generate a preview of a specified voice with hardcoded settings.
+curl -X POST "http://127.0.0.1:7851/api/previewvoice/" -F "voice=female_01.wav"
+Replace female_01.wav with the name of the voice sample you want to hear.
+JSON return: {"status": "generate-success", "output_file_path": "/path/to/outputs/api_preview_voice.wav", "output_file_url": "http://127.0.0.1:7851/audio/api_preview_voice.wav"}
+