OcrController.java 1.15 KB
package com.xly.ocr.web;

import com.xly.ocr.service.OcrService;
import com.xly.tts.bean.TTSResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/ocr")
public class OcrController {

    @Autowired
    private OcrService ocrService;

    @PostMapping("/extract")
    public ResponseEntity<TTSResponseDTO> extractText(
            @RequestParam("file") MultipartFile file) {
        String result = ocrService.extractTextFromMultipartFile(file);
        TTSResponseDTO dto= TTSResponseDTO.builder()
                .code(200)
                .message("操作成功")
                .processedText(result)
                .build();
        return ResponseEntity.ok(dto);
    }

    @PostMapping("/batch")
    public ResponseEntity<List<String>> batchExtract(
            @RequestParam("files") List<MultipartFile> files) {
        List<String> results = ocrService.batchExtractText(files);
        return ResponseEntity.ok(results);
    }
}