|
@@ -1,8 +1,6 @@
|
|
|
package com.zhili.stationcontrol.tts.controller;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.zhili.stationcontrol.tts.service.MusicService;
|
|
|
-import com.zhili.stationcontrol.tts.util.WavPlayUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -11,15 +9,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.sound.sampled.AudioInputStream;
|
|
|
-import javax.sound.sampled.AudioSystem;
|
|
|
-import javax.sound.sampled.Clip;
|
|
|
-import javax.sound.sampled.LineUnavailableException;
|
|
|
-import javax.sound.sampled.UnsupportedAudioFileException;
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author :HuangBin
|
|
@@ -77,7 +67,7 @@ public class TtsController {
|
|
|
public String startMusic(@PathVariable Integer vol) {
|
|
|
vol = vol > 1000 ? 1000 : vol;
|
|
|
vol = vol < 0 ? 0 : vol;
|
|
|
- log.info("start music with vol:{}", vol);
|
|
|
+ //log.info("start music with vol:{}", vol);
|
|
|
Integer start = musicService.start(playPath, vol);
|
|
|
return start.equals(0) ? "ok" : "error";
|
|
|
}
|
|
@@ -89,24 +79,9 @@ public class TtsController {
|
|
|
return "ok";
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/music")
|
|
|
- public String music() throws UnsupportedAudioFileException, IOException, LineUnavailableException, InterruptedException {
|
|
|
-// File file = new File("/static/wav/hdzqdd.wav");
|
|
|
-// // 创建一个AudioInputStream
|
|
|
-// AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
|
|
|
-// // 使用Clip类来处理音频流
|
|
|
-// Clip clip = AudioSystem.getClip();
|
|
|
-// // 打开声卡并加载音频数据
|
|
|
-// clip.open(audioInputStream);
|
|
|
-// // 开始播放
|
|
|
-// clip.start();
|
|
|
-// Thread.sleep(clip.getMicrosecondLength() / 1000);
|
|
|
-// // 等待音频播放完成
|
|
|
-// clip.drain();
|
|
|
-// // 关闭声卡
|
|
|
-// clip.close();
|
|
|
- String path = "/static/wav/hdzqdd.wav";
|
|
|
- //log.info("path:{}", path);
|
|
|
+ @GetMapping("/speak/{file}")
|
|
|
+ public String speak(@PathVariable String file) throws IOException, InterruptedException {
|
|
|
+ String path = "/static/mp3/" +file+".wav";
|
|
|
Process exec = Runtime.getRuntime().exec("play " + path);
|
|
|
exec.waitFor();
|
|
|
return "ok";
|