Skip to content

Commit

Permalink
feat: 调整包结构
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyueyi committed May 3, 2024
1 parent 5921226 commit 2b46128
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 13 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.github.hui.quick.plugin.tts;

import com.github.hui.quick.plugin.tts.constant.VoiceEnum;
import com.github.hui.quick.plugin.tts.model.SSML;
import com.github.hui.quick.plugin.tts.service.TTSService;

import java.util.Optional;

/**
* @author YiHui
* @date 2024/4/30
*/
public class TtsWrapper {
public String BASE = "d://tmp/audio/";
private volatile TTSService ttsService;
private volatile long lastVisit = 0L;

private TtsWrapper() {
}

private static volatile TtsWrapper instance;

public static TtsWrapper getInstance() {
if (instance == null) {
synchronized (TtsWrapper.class) {
if (instance == null) {
instance = new TtsWrapper();
}
}
}
return instance;
}


/**
* 获取音色
*
* @param voice
* @return
*/
public VoiceEnum fromVoice(String voice) {
return Optional.ofNullable(VoiceEnum.of(voice)).orElse(VoiceEnum.zh_CN_XiaoxiaoNeural);
}

private void init() {
ttsService = new TTSService();
ttsService.setBaseSavePath(BASE);
lastVisit = System.currentTimeMillis();
}

public TTSService getTts() {
if (System.currentTimeMillis() - lastVisit >= 60_000) {
if (ttsService != null) {
ttsService.close();
}
init();
}
lastVisit = System.currentTimeMillis();
return this.ttsService;
}

public void sendTxt(SSML txt) {
getTts().sendText(txt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public interface TtsConstants {
String AUDIO_CONTENT_TYPE = "Content-Type:audio";


public static String buildWsUrl() {
/**
* 构建转tts的长连接
*
* @return ws长连接地址
*/
static String buildWsUrl() {
return TtsConstants.EDGE_SPEECH_WSS + "?Retry-After=200&TrustedClientToken=" + TtsConstants.TRUSTED_CLIENT_TOKEN + "&ConnectionId=" + TtsTools.getRandomId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,13 @@ public String getGender() {
public String getLocale() {
return locale;
}

public static VoiceEnum of(String name) {
for (VoiceEnum v : VoiceEnum.values()) {
if (v.name().equalsIgnoreCase(name)) {
return v;
}
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ private synchronized WebSocket getOrCreateWs() {

private OkHttpClient getOkHttpClient() {
if (okHttpClient == null) {
okHttpClient = new OkHttpClient.Builder().pingInterval(20, TimeUnit.SECONDS) // 设置 PING 帧发送间隔
okHttpClient = new OkHttpClient.Builder()
// 设置 PING 帧发送间隔
.pingInterval(20, TimeUnit.SECONDS)
.build();
}
return okHttpClient;
Expand Down
File renamed without changes.

0 comments on commit 2b46128

Please sign in to comment.