1 changed files with 50 additions and 0 deletions
@ -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(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue