|
|
|
|
|
from fastapi import APIRouter, Depends |
|
from auth import UserCreate |
|
from main import get_current_user |
|
|
|
import onnxruntime |
|
import numpy as np |
|
|
|
def tts_synthesis(text, onnx_model_path): |
|
|
|
session = onnxruntime.InferenceSession(onnx_model_path) |
|
|
|
|
|
input_name = session.get_inputs()[0].name |
|
input_data = np.array([text], dtype=np.str).reshape(1, 1) |
|
|
|
|
|
output_name = session.get_outputs()[0].name |
|
output = session.run([output_name], {input_name: input_data}) |
|
|
|
|
|
audio_data = output[0] |
|
|
|
|
|
return audio_data |
|
|
|
router = APIRouter() |
|
|
|
@router.get("/synthesize", response_model=UserCreate) |
|
def synthesize_text(text: str, current_user: str = Depends(get_current_user)): |
|
|
|
audio_data = tts_synthesis(text, current_user) |
|
return {"user": current_user, "audio_data": audio_data} |
|
|