pi.tts
Browse files- App/TTS/TTSRoutes.py +4 -0
- App/TTS/utils/Pi.py +2 -0
- App/app.py +1 -3
App/TTS/TTSRoutes.py
CHANGED
@@ -17,6 +17,7 @@ from App import pi
|
|
17 |
from .utils.Descript import DescriptTTS
|
18 |
import os
|
19 |
import asyncio
|
|
|
20 |
|
21 |
from fastapi import FastAPI, Request, HTTPException
|
22 |
from fastapi.responses import StreamingResponse, FileResponse
|
@@ -34,6 +35,7 @@ data = {
|
|
34 |
|
35 |
descript_tts = DescriptTTS()
|
36 |
heyGentts = HeygenAPI(**data)
|
|
|
37 |
|
38 |
|
39 |
@tts_router.post("/generate_tts")
|
@@ -97,6 +99,8 @@ async def search_id(req: StatusRequest):
|
|
97 |
|
98 |
@tts_router.post("/pi_tts")
|
99 |
async def pi_tts(req: PiTTSRequest):
|
|
|
|
|
100 |
return await pi.say(text=req.text, voice=req.voice)
|
101 |
|
102 |
|
|
|
17 |
from .utils.Descript import DescriptTTS
|
18 |
import os
|
19 |
import asyncio
|
20 |
+
from .utils.Pi import PiAIClient
|
21 |
|
22 |
from fastapi import FastAPI, Request, HTTPException
|
23 |
from fastapi.responses import StreamingResponse, FileResponse
|
|
|
35 |
|
36 |
descript_tts = DescriptTTS()
|
37 |
heyGentts = HeygenAPI(**data)
|
38 |
+
pi = PiAIClient(headless=True)
|
39 |
|
40 |
|
41 |
@tts_router.post("/generate_tts")
|
|
|
99 |
|
100 |
@tts_router.post("/pi_tts")
|
101 |
async def pi_tts(req: PiTTSRequest):
|
102 |
+
if not pi.initialized:
|
103 |
+
await pi.setup()
|
104 |
return await pi.say(text=req.text, voice=req.voice)
|
105 |
|
106 |
|
App/TTS/utils/Pi.py
CHANGED
@@ -34,6 +34,7 @@ class PiAIClient:
|
|
34 |
self.browser = None
|
35 |
self.context = None
|
36 |
self.page = None
|
|
|
37 |
|
38 |
# Define actions with their selectors and corresponding handler methods
|
39 |
self.actions = [
|
@@ -79,6 +80,7 @@ class PiAIClient:
|
|
79 |
|
80 |
# Mapping from sid to (Future, VoiceType)
|
81 |
self.sid_futures = asyncio.Queue()
|
|
|
82 |
|
83 |
def ensure_download_directory(self):
|
84 |
"""Ensure that the downloads directory exists."""
|
|
|
34 |
self.browser = None
|
35 |
self.context = None
|
36 |
self.page = None
|
37 |
+
self.initialized = False
|
38 |
|
39 |
# Define actions with their selectors and corresponding handler methods
|
40 |
self.actions = [
|
|
|
80 |
|
81 |
# Mapping from sid to (Future, VoiceType)
|
82 |
self.sid_futures = asyncio.Queue()
|
83 |
+
self.initialized = True
|
84 |
|
85 |
def ensure_download_directory(self):
|
86 |
"""Ensure that the downloads directory exists."""
|
App/app.py
CHANGED
@@ -4,7 +4,7 @@ from fastapi.middleware.gzip import GZipMiddleware
|
|
4 |
|
5 |
from .TTS.TTSRoutes import tts_router
|
6 |
from .Embedding.EmbeddingRoutes import embeddigs_router
|
7 |
-
|
8 |
|
9 |
from fastapi.middleware.cors import CORSMiddleware
|
10 |
|
@@ -33,13 +33,11 @@ app.add_middleware(
|
|
33 |
allow_headers=["*"],
|
34 |
)
|
35 |
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
36 |
-
pi = PiAIClient(headless=True)
|
37 |
|
38 |
|
39 |
@app.on_event("startup")
|
40 |
async def startup():
|
41 |
FastAPICache.init(InMemoryBackend())
|
42 |
-
await pi.setup()
|
43 |
|
44 |
|
45 |
@app.get("/")
|
|
|
4 |
|
5 |
from .TTS.TTSRoutes import tts_router
|
6 |
from .Embedding.EmbeddingRoutes import embeddigs_router
|
7 |
+
|
8 |
|
9 |
from fastapi.middleware.cors import CORSMiddleware
|
10 |
|
|
|
33 |
allow_headers=["*"],
|
34 |
)
|
35 |
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
|
36 |
|
37 |
|
38 |
@app.on_event("startup")
|
39 |
async def startup():
|
40 |
FastAPICache.init(InMemoryBackend())
|
|
|
41 |
|
42 |
|
43 |
@app.get("/")
|