package com.supervision.controller;

import com.supervision.dto.paddlespeech.res.TtsResultDTO;
import com.supervision.service.VoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Objects;

@Slf4j
@Api(tags = "音频处理")
@RequestMapping("voice")
@RequiredArgsConstructor
@RestController
public class VoiceController {

    private final VoiceService voiceService;

    @ApiOperation("语音转文字")
    @PostMapping("voiceToText")
    public String voiceToText(MultipartFile file, String sessionId) throws IOException {

        return  voiceService.voiceToText(file,sessionId);
    }

    @ApiOperation("文字转语音")
    @PostMapping("textToVoice")
    public String textToVoice(String text){
        TtsResultDTO ttsResultDTO = voiceService.textToVoice(text);
        if (Objects.isNull(ttsResultDTO)){
            return null;
        }
        return ttsResultDTO.getAudio();
    }
}
