//package com.ruoyi.aicall.tts.doubao;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.ruoyi.aicall.utils.PcmToWavConverter;
//import com.ruoyi.aicall.utils.WavFileWriter;
//import okhttp3.*;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import java.io.IOException;
//import java.util.UUID;
//
//public class TtsHttpDemo {
//    private static final Logger log = LoggerFactory.getLogger(TtsHttpDemo.class);
//
//    public static void main(String[] args) throws IOException {
//        // set your appid and access_token
//        String API_URL = "https://openspeech.bytedance.com/api/v1/tts";
//        String appid = "8380189306";
//        String accessToken = "esgS1pvKY_jdvpDezc0EFjJbYGPVTY7j";
//        String voiceType = "BV001_streaming";
//        String text = "您好，请问您是张三先生吗";
//
//        TtsRequest ttsRequest = TtsRequest.builder()
//            .app(TtsRequest.App.builder()
//                .appid(appid)
//                .cluster("volcano_tts")
//                .build())
//            .user(TtsRequest.User.builder()
//                .uid("uid")
//                .build())
//            .audio(TtsRequest.Audio.builder()
//                .encoding("wav")
//                .voiceType(voiceType)
//                .build())
//            .request(TtsRequest.Request.builder()
//                .reqID(UUID.randomUUID().toString())
//                .operation("query")
//                .text(text)
//                .build())
//            .build();
//
//
//        String reqBody = JSON.toJSONString(ttsRequest);
//        log.info("request: {}", reqBody);
//
//        OkHttpClient client = new OkHttpClient();
//        RequestBody body = RequestBody.create(MediaType.get("application/json; charset=utf-8"), reqBody);
//        Request request = new Request.Builder()
//            .url(API_URL)
//            .header("Authorization", "Bearer;" + accessToken)
//            .post(body)
//            .build();
//
//        Response response = client.newCall(request).execute();
//        JSONObject result = JSONObject.parseObject(response.body().string());
//        log.info("response: {}", result.getString("data"));
//        WavFileWriter.writeWavFromBase64(result.getString("data"), "D://file/1.wav");
//        System.exit(0);
//    }
//}
