auto refresh and hello
Browse files- App/TTS/TTSRoutes.py +15 -4
- App/TTS/utils/Descript.py +1 -0
App/TTS/TTSRoutes.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
|
| 3 |
|
| 4 |
-
from .Schemas import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
from .utils.Podcastle import PodcastleAPI
|
| 6 |
from .utils.HeyGen import HeygenAPI
|
| 7 |
from .utils.Descript import DescriptTTS
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
tts_router = APIRouter(tags=["TTS"])
|
| 11 |
data = {"username": os.environ.get("USERNAME"), "password": os.environ.get("PASSWORD")}
|
|
@@ -16,7 +24,7 @@ data = {
|
|
| 16 |
"token": os.environ.get("HEYGEN_TOKEN"),
|
| 17 |
}
|
| 18 |
|
| 19 |
-
descript_tts=DescriptTTS()
|
| 20 |
heyGentts = HeygenAPI(**data)
|
| 21 |
|
| 22 |
|
|
@@ -31,6 +39,7 @@ async def generate_heygen_voice(req: HeyGenTTSRequest):
|
|
| 31 |
print("hey gen here")
|
| 32 |
return await heyGentts.tts_request(req)
|
| 33 |
|
|
|
|
| 34 |
@tts_router.post("/descript_tts")
|
| 35 |
async def generate_descript_voice(req: DescriptRequest):
|
| 36 |
return await descript_tts.overdub_text(**req.__dict__)
|
|
@@ -40,16 +49,17 @@ async def generate_descript_voice(req: DescriptRequest):
|
|
| 40 |
async def status_descript(req: DescriptStatusRequest):
|
| 41 |
return await descript_tts.request_status(req.id)
|
| 42 |
|
|
|
|
| 43 |
@tts_router.post("/descript_sfx")
|
| 44 |
async def descript_sfx(req: DescriptSfxRequest):
|
| 45 |
return await descript_tts.search_sound_effects(req.query)
|
| 46 |
|
|
|
|
| 47 |
@tts_router.post("/descript_unsplash")
|
| 48 |
async def descript_unsplash(req: DescriptSfxRequest):
|
| 49 |
return await descript_tts.search_unsplash_images(req.query)
|
| 50 |
|
| 51 |
|
| 52 |
-
|
| 53 |
@tts_router.get("/descript_voices")
|
| 54 |
async def voices_descript():
|
| 55 |
return await descript_tts.get_voices()
|
|
@@ -57,7 +67,8 @@ async def voices_descript():
|
|
| 57 |
|
| 58 |
@tts_router.get("/descript_auto_refresh")
|
| 59 |
async def auto_refresh():
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
@tts_router.post("/status")
|
|
|
|
| 1 |
from fastapi import APIRouter
|
| 2 |
|
| 3 |
|
| 4 |
+
from .Schemas import (
|
| 5 |
+
StatusRequest,
|
| 6 |
+
TTSGenerateRequest,
|
| 7 |
+
HeyGenTTSRequest,
|
| 8 |
+
DescriptRequest,
|
| 9 |
+
DescriptStatusRequest,
|
| 10 |
+
DescriptSfxRequest,
|
| 11 |
+
)
|
| 12 |
from .utils.Podcastle import PodcastleAPI
|
| 13 |
from .utils.HeyGen import HeygenAPI
|
| 14 |
from .utils.Descript import DescriptTTS
|
| 15 |
import os
|
| 16 |
+
import asyncio
|
| 17 |
|
| 18 |
tts_router = APIRouter(tags=["TTS"])
|
| 19 |
data = {"username": os.environ.get("USERNAME"), "password": os.environ.get("PASSWORD")}
|
|
|
|
| 24 |
"token": os.environ.get("HEYGEN_TOKEN"),
|
| 25 |
}
|
| 26 |
|
| 27 |
+
descript_tts = DescriptTTS()
|
| 28 |
heyGentts = HeygenAPI(**data)
|
| 29 |
|
| 30 |
|
|
|
|
| 39 |
print("hey gen here")
|
| 40 |
return await heyGentts.tts_request(req)
|
| 41 |
|
| 42 |
+
|
| 43 |
@tts_router.post("/descript_tts")
|
| 44 |
async def generate_descript_voice(req: DescriptRequest):
|
| 45 |
return await descript_tts.overdub_text(**req.__dict__)
|
|
|
|
| 49 |
async def status_descript(req: DescriptStatusRequest):
|
| 50 |
return await descript_tts.request_status(req.id)
|
| 51 |
|
| 52 |
+
|
| 53 |
@tts_router.post("/descript_sfx")
|
| 54 |
async def descript_sfx(req: DescriptSfxRequest):
|
| 55 |
return await descript_tts.search_sound_effects(req.query)
|
| 56 |
|
| 57 |
+
|
| 58 |
@tts_router.post("/descript_unsplash")
|
| 59 |
async def descript_unsplash(req: DescriptSfxRequest):
|
| 60 |
return await descript_tts.search_unsplash_images(req.query)
|
| 61 |
|
| 62 |
|
|
|
|
| 63 |
@tts_router.get("/descript_voices")
|
| 64 |
async def voices_descript():
|
| 65 |
return await descript_tts.get_voices()
|
|
|
|
| 67 |
|
| 68 |
@tts_router.get("/descript_auto_refresh")
|
| 69 |
async def auto_refresh():
|
| 70 |
+
asyncio.create_task(descript_tts.start_token_refresh_schedule())
|
| 71 |
+
return {"message": "Token refresh schedule started in the background."}
|
| 72 |
|
| 73 |
|
| 74 |
@tts_router.post("/status")
|
App/TTS/utils/Descript.py
CHANGED
|
@@ -257,6 +257,7 @@ class DescriptTTS:
|
|
| 257 |
if response.status < 300:
|
| 258 |
return await response.json()
|
| 259 |
elif response.status == 401:
|
|
|
|
| 260 |
# Retry the request after refreshing the token
|
| 261 |
await self.login_and_get_bearer_token()
|
| 262 |
headers["authorization"] = f"Bearer {self.bearer_token}"
|
|
|
|
| 257 |
if response.status < 300:
|
| 258 |
return await response.json()
|
| 259 |
elif response.status == 401:
|
| 260 |
+
self.refresh_token =None
|
| 261 |
# Retry the request after refreshing the token
|
| 262 |
await self.login_and_get_bearer_token()
|
| 263 |
headers["authorization"] = f"Bearer {self.bearer_token}"
|