-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
plugins/tts-plugin/src/com/github/hui/quick/plugin/tts/TtsWrapper.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
plugins/tts-plugin/src/main/java/com/github/hui/quick/plugin/tts/TtsWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.