From 954516795b1282aba86795c38896921ca3f19578 Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Tue, 22 Jun 2021 10:06:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E5=90=88=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ccsens/ht/api/BaiDuController.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 ht/src/main/java/com/ccsens/ht/api/BaiDuController.java diff --git a/ht/src/main/java/com/ccsens/ht/api/BaiDuController.java b/ht/src/main/java/com/ccsens/ht/api/BaiDuController.java new file mode 100644 index 00000000..89e228fc --- /dev/null +++ b/ht/src/main/java/com/ccsens/ht/api/BaiDuController.java @@ -0,0 +1,50 @@ +package com.ccsens.ht.api; + +import com.alibaba.fastjson.JSONObject; +import com.ccsens.cloudutil.annotation.MustLogin; +import com.ccsens.util.RestTemplateUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; +import sun.misc.BASE64Decoder; + +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletResponse; +import java.io.*; + +/** + * @description: + * @author: whj + * @time: 2021/6/22 8:56 + */ +@Slf4j +@Api(tags = "百度相关",value = "百度相关") +@RestController +public class BaiDuController { + + + @ApiOperation(value = "合成语音",notes = "合成语音") + @RequestMapping(value = "/yuyin", method = RequestMethod.GET) + public void yuyin(String text, HttpServletResponse response) throws IOException { + try { + response.setHeader("content-disposition", "attachment;fileName=yuyin.mp3"); + String result = RestTemplateUtil.postUrlEncode("https://cloud.baidu.com/aidemo?type=tns&per=4119&spd=1&pit=5&vol=5&aue=6&tex=" + text, new JSONObject()); + JSONObject jsonObject = JSONObject.parseObject(result); + String data = jsonObject.getString("data").replace("data:audio/x-mpeg;base64,", ""); + log.info("data:{}",data); + byte[] buffer = new BASE64Decoder().decodeBuffer(data); + OutputStream out = response.getOutputStream(); + out.write(buffer); + out.close(); + }catch (Exception e) { + e.printStackTrace(); + } + } + +}