kavlab commited on
Commit
8a3847d
·
1 Parent(s): 5a8691c

added kuznetsov_av/api.py

Browse files
Files changed (1) hide show
  1. kuznetsov_av/api.py +31 -0
kuznetsov_av/api.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import text_to_speech_converter as t2s
4
+ import base64
5
+
6
+ class Request(BaseModel):
7
+ """
8
+ Input text.
9
+ """
10
+ text: str
11
+
12
+ class Response(BaseModel):
13
+ """
14
+ Result of text-to-audio generation.
15
+ audio - base64 string
16
+ """
17
+ audio: str
18
+ sampling_rate: int
19
+
20
+
21
+ app = FastAPI()
22
+
23
+ @app.post('/text-to-speach/')
24
+ def text_to_speach(entity: Request) -> Response:
25
+ """
26
+ Text-to-audio generation method using text_to_speech_converter.
27
+ """
28
+ synthesiser = t2s.load_model()
29
+ embeddings_dataset = t2s.load_speaker_dataset()
30
+ audio, sampling_rate = t2s.text_to_speech(entity.text, synthesiser, embeddings_dataset)
31
+ return Response(audio=base64.b32encode(audio), sampling_rate=sampling_rate)