package com.rj.service;

import com.rj.dto.AsrRequest;
import com.rj.dto.AsrResponse;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * TtsRequestLogService ASR功能测试类
 * 
 * @author rj
 * @date 2025-01-02
 */
@SpringBootTest
public class TtsRequestLogServiceAsrTest {
    
    @Autowired
    private ITtsRequestLogService ttsRequestLogService;
    
    @Test
    public void testSpeechToText() {
        // 创建测试请求
        AsrRequest request = new AsrRequest();
        request.setAudioUrl("https://api.huayang-star.com/api/audio/1957424645898579969_a2db5d76-b52c-4289-9c7e-ed55d7f15e42.mp3");
        request.setModel("paraformer-v2");
        request.setFormat("mp3");
        request.setSampleRate(16000);
        request.setEnablePunctuation(true);
        request.setEnableNumberConversion(true);
        request.setCreatorName("测试用户");
        request.setCreatorPhone("13800138000");
        request.setAudioName("测试音频");
        
        // 执行语音识别
        AsrResponse response = ttsRequestLogService.speechToText(request);
        
        // 打印结果
        System.out.println("识别结果: " + response.isSuccess());
        System.out.println("识别文本: " + response.getText());
        System.out.println("处理时间: " + response.getProcessingTimeMs() + "ms");
        System.out.println("任务ID: " + response.getTaskId());
        System.out.println("请求ID: " + response.getRequestId());
        
        if (response.getResults() != null && !response.getResults().isEmpty()) {
            System.out.println("结果详情:");
            for (AsrResponse.AsrResult result : response.getResults()) {
                System.out.println("  文本: " + result.getText());
                System.out.println("  开始时间: " + result.getStartTime());
                System.out.println("  结束时间: " + result.getEndTime());
                System.out.println("  说话人ID: " + result.getSpeakerId());
                System.out.println("  置信度: " + result.getConfidence());
            }
        }
    }
    
    @Test
    public void testAsrServiceAvailable() {
        boolean available = ttsRequestLogService.isAsrServiceAvailable();
        System.out.println("ASR服务是否可用: " + available);
    }
}

