package com.ruoyi.ibs.audio.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.ibs.audio.domain.AudioUploadDTO;
import com.ruoyi.ibs.audio.service.AudioService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 吴凯程
 * @Date 2025/11/21
 **/
@Api(tags = "语音转文字接口")
@RequestMapping("/audio")
@RestController
public class AudioController extends BaseController {

    @Resource
    private AudioService audioService;

    @PostMapping("/upload")
    @ApiOperation("上传语音接口")
    public AjaxResult uploadAudio(AudioUploadDTO audioUploadDTO) {
        return AjaxResult.success(audioService.uploadAudioAnalysis(audioUploadDTO));
    }

    @GetMapping("/get")
    @ApiOperation("获取语音转文字结果")
    public AjaxResult getRadioAnalysis(@RequestParam String uuid) {
        String audioAnalysis = audioService.getAudioAnalysis(uuid);
        if (audioAnalysis.equals(AudioService.AUDIO_ERROR_CODE)) {
            return AjaxResult.error("语音转文字失败");
        }
        return AjaxResult.success(audioAnalysis);
    }

}
