dmkl commited on
Commit
dbf58fe
·
1 Parent(s): 2772ac2

Fix handler

Browse files
Files changed (1) hide show
  1. handler.py +18 -11
handler.py CHANGED
@@ -3,19 +3,26 @@ import torch
3
  import numpy as np
4
  import scipy
5
  import io
 
6
 
7
- preload_models()
 
 
8
 
9
- def infer(inputs):
10
- text = inputs.get("text", "")
11
- if not text.strip():
12
- return {"error": "No input text provided."}
13
 
14
- audio_array = generate_audio(text, history_prompt="v2/ru_speaker_0")
15
 
16
- # Сохраняем в wav-поток
17
- byte_io = io.BytesIO()
18
- scipy.io.wavfile.write(byte_io, rate=24000, data=audio_array)
19
- byte_io.seek(0)
20
 
21
- return {"audio": byte_io.read()}
 
 
 
 
 
 
3
  import numpy as np
4
  import scipy
5
  import io
6
+ import base64
7
 
8
+ class EndpointHandler:
9
+ def __init__(self, path=""):
10
+ preload_models()
11
 
12
+ def __call__(self, data):
13
+ text = data.get("inputs", "")
14
+ if not text.strip():
15
+ return {"error": "No input text provided."}
16
 
17
+ audio_array = generate_audio(text, history_prompt="v2/ru_speaker_0")
18
 
19
+ byte_io = io.BytesIO()
20
+ scipy.io.wavfile.write(byte_io, rate=24000, data=audio_array)
21
+ byte_io.seek(0)
 
22
 
23
+ audio_base64 = base64.b64encode(byte_io.read()).decode("utf-8")
24
+
25
+ return {
26
+ "audio_base64": audio_base64,
27
+ "content_type": "audio/wav"
28
+ }