Gregniuki commited on
Commit
72f77dc
1 Parent(s): f46aecc

Update tts.py

Browse files
Files changed (1) hide show
  1. tts.py +21 -0
tts.py CHANGED
@@ -5,6 +5,27 @@ from auth import UserCreate # Import a model for the user response
5
  from tts import tts_synthesis # Import your TTS synthesis function
6
  from main import get_current_user
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  router = APIRouter()
9
 
10
  @router.get("/synthesize", response_model=UserCreate)
 
5
  from tts import tts_synthesis # Import your TTS synthesis function
6
  from main import get_current_user
7
 
8
+ import onnxruntime
9
+ import numpy as np
10
+
11
+ def tts_synthesis(text, onnx_model_path):
12
+ # Load the ONNX model
13
+ session = onnxruntime.InferenceSession(onnx_model_path)
14
+
15
+ # Prepare input data
16
+ input_name = session.get_inputs()[0].name
17
+ input_data = np.array([text], dtype=np.str).reshape(1, 1)
18
+
19
+ # Run inference
20
+ output_name = session.get_outputs()[0].name
21
+ output = session.run([output_name], {input_name: input_data})
22
+
23
+ # Extract audio data
24
+ audio_data = output[0]
25
+
26
+ # Return the audio data
27
+ return audio_data
28
+
29
  router = APIRouter()
30
 
31
  @router.get("/synthesize", response_model=UserCreate)