package thyyxxk.webserver.controller.outpatient.voice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.service.externalhttp.ThirdpartApiService;
import thyyxxk.webserver.utils.ResultVoUtil;
import thyyxxk.webserver.utils.SnowFlakeId;

/**
 * @description: 生成语音文件接口
 * @author: DingJie
 * @create: 2021/7/299:23
 */
@RestController
@RequestMapping("/voice")
public class VoiceController {
    private final ThirdpartApiService thirdpartApi;

    @Autowired
    public VoiceController(ThirdpartApiService thirdpartApi) {
        this.thirdpartApi = thirdpartApi;
    }

    @PassToken
    @GetMapping("/textToSpeech")
    public ResultVo<String> textToSpeech(@RequestParam("text") String text) {
        String id = SnowFlakeId.instance().nextId();
        String url = thirdpartApi.getSpeechUrl(text, id);
        return ResultVoUtil.success(url);
    }

}
