File size: 1,180 Bytes
01e655b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pydantic import BaseModel


from modules.speaker import speaker_mgr


from modules.data import styles_mgr


from modules.api import utils as api_utils
from modules.api.Api import APIManager


async def list_styles():
    return {"message": "ok", "data": styles_mgr.list_items()}


async def list_speakers():
    return {
        "message": "ok",
        "data": [spk.to_json() for spk in speaker_mgr.list_speakers()],
    }


class CreateSpeaker(BaseModel):
    seed: int
    name: str = ""


async def create_speaker(request: CreateSpeaker):
    speaker = speaker_mgr.create_speaker(request.seed, request.name)
    return {"message": "ok", "data": speaker.to_json()}


async def refresh_speakers():
    speaker_mgr.refresh_speakers()
    return {"message": "ok"}


def setup(app: APIManager):
    app.get("/v1/styles/list", response_model=api_utils.BaseResponse)(list_styles)
    app.get("/v1/speakers/list", response_model=api_utils.BaseResponse)(list_speakers)
    app.post("/v1/speaker/create", response_model=api_utils.BaseResponse)(
        create_speaker
    )
    app.post("/v1/speaker/refresh", response_model=api_utils.BaseResponse)(
        refresh_speakers
    )