hby100japp功能3

This commit is contained in:
2026-02-06 11:50:38 +08:00
parent 855714106e
commit f3551be093
16 changed files with 305 additions and 67 deletions

View File

@ -137,7 +137,7 @@ public class AppDeviceHBY100JController extends BaseController {
*/
private Integer voiceStrobeAlarm;
/**
* 0 公安,1消防,2应急,3交警4 市政5 铁路6 医疗7部队8 水利,9 语音
* 0 公安,1消防,2应急,3交警4 市政5 铁路6 医疗7语音
*/
private Integer mode;

View File

@ -47,22 +47,25 @@ public class HttpTtsClient {
/**
* 使用HTTP POST方式调用阿里云TTS服务生成MP3格式语音
*/
public byte[] synthesizeTextToMp3(String text) throws IOException {
public byte[] synthesizeTextToMp3(String text,String fileSuffix) throws IOException {
String endpoint = "https://nls-gateway-cn-shanghai.aliyuncs.com/stream/v1/tts";
// 构建请求体
// String requestBody = String.format(
// "{\"appkey\":\"%s\",\"text\":\"%s\",\"voice\":\"zhifeng\",\"format\":\"MP3\",\"sample_rate\":24000,\"volume\":50,\"speech_rate\":0,\"pitch_rate\":0}",
// appKey,
// text.replace("\"", "\\\"")
// text.replace("\"", "\\\"")zhide
// );
String token = refreshAccessToken();
String requestBody = " {\n" +
" \"appkey\":\""+appKey+"\",\n" +
" \"voice\":\"zhide\",\n" +
" \"text\":\""+text+"\",\n" +
" \"token\":\""+token+"\",\n" +
" \"format\":\"mp3\"\n" +
" \"volume\": 100,\n" +
" \"pitch_rate\": 0,\n" +
" \"format\":\""+fileSuffix+"\"\n" +
" }";
URL url = new URL(endpoint);
@ -119,7 +122,7 @@ public class HttpTtsClient {
* 保存MP3到文件
*/
public String saveMp3ToFile(String text, String outputPath) throws IOException {
byte[] mp3Data = synthesizeTextToMp3(text);
byte[] mp3Data = synthesizeTextToMp3(text,"mp3");
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
fos.write(mp3Data);

View File

@ -19,8 +19,8 @@ public class HttpTtsExample {
// 使用HTTP方式调用
HttpTtsClient httpClient = new HttpTtsClient(accessKeyId, accessKeySecret, appKey);
String text = "大江东去,浪淘尽,千古风流人物。故垒西边,人道是,三国周郎赤壁。乱石穿空,惊涛拍岸,卷起千堆雪";
String outputPath = "D:\\http_output9.mp3";
String text = "前方拥堵,请绕道而行";
String outputPath = "D:\\http_output11.mp3";
String resultFile = httpClient.saveMp3ToFile(text, outputPath);
System.out.println("MP3音频已保存至: " + resultFile);

View File

@ -454,7 +454,7 @@ public class AudioProcessService {
// 使用HTTP方式调用
HttpTtsClient httpClient = new HttpTtsClient(accessKeyId, accessKeySecret, appKey);
//
byte[] mp3Data = httpClient.synthesizeTextToMp3(text);
byte[] mp3Data = httpClient.synthesizeTextToMp3(text,fileSuffix);
// byte[] mp3Data = alibabaTTSUtil.synthesizeTextToMp3(text);
SysOssVo upload = ossService.upload(mp3Data, generateRandomFileName(fileSuffix));