package com.gyee.frame.controller.ticket;

import com.gyee.frame.common.domain.AjaxResult;
import com.gyee.frame.model.ticket.TokenUser;
import com.gyee.frame.service.ticket.ShiroService;
import com.gyee.frame.service.ticket.SpeechService;
import com.gyee.frame.util.ticket.TicketUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/speech")
public class SpeechController {

    @Autowired
    SpeechService speechService;
    @Autowired
    ShiroService shiroService;

//    @PostMapping(value = "tts")
//    public void tts(@RequestParam("text") String text){
//        speechService.textToVoice(text);
//    }

    @PostMapping(value = "tts")
    public AjaxResult tts(@RequestHeader("token") String header, @RequestParam("text") String text){
        TokenUser user = shiroService.findToken(header);
        String path = TicketUtil.absolutePath() + "\\src\\main\\resources\\speech\\" + user.getLaborNum() + ".wav";
        path = path.replace("\\", "/");
        boolean result = speechService.textToVoice(text,  path);
        if (result)
            return AjaxResult.success();
        return AjaxResult.error(4004, "语音合成失败");
    }
}
