package com.cmvr.llm.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.cmvr.common.utils.http.CallAPIUtil;
import com.cmvr.llm.service.LLMAiAgentPlatformService;
import com.cmvr.llm.service.LLMAiTtsService;
import com.cmvr.llm.util.LlmChatService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class LLMAiTtsServiceImpl implements LLMAiTtsService {
    @Override
    public JSONObject play(String url, String text, String voice, String speed, String volume) {
//        Map<String, Object> body = new HashMap<>();
//        body.put("Query", text);
//        long startTime = System.currentTimeMillis();
//        String result = null;
//        try {
//            result = llmChatService.chat(
//                    apiKey,  // apiKey (header用)
//                    apiKey,  // apiId (body的AppKey)
//                    "user_123",               // userId
//                    body
//            );
//            System.out.println( result);
//            System.out.println("总耗时：" + (System.currentTimeMillis() - startTime));
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
        // 通过post调用tts接口
        String result = CallAPIUtil.doPostJson(url, new HashMap<>(), new JSONObject().fluentPut("text", text).fluentPut("voice", voice).fluentPut("speed", speed).fluentPut("volume", volume));

        return new JSONObject().fluentPut("result", result);
    }
}
