TTS 返回语音优化

This commit is contained in:
2025-10-19 09:23:08 +08:00
parent d58fa13356
commit 060ba472c7
2 changed files with 14 additions and 10 deletions

View File

@@ -53,7 +53,7 @@ public class ElevenLabsClient {
Map<String, Object> payload = new HashMap<>();
payload.put("text", text);
payload.put("model_id", modelId);
payload.put("voice_settings", new VoiceSettings(0.8, 0.5,1));
payload.put("voice_settings", new VoiceSettings(0.8, 0.5,1,0));
Gson gson = new Gson();
StringEntity entity = new StringEntity(gson.toJson(payload), ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
@@ -102,14 +102,15 @@ public class ElevenLabsClient {
public String handleTextToVoice(String inputText,String outputFile){
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
// 获取可用语音
VoicesResponse voicesResponse = getVoices(httpClient);
if (voicesResponse != null && voicesResponse.getVoices() != null
&& voicesResponse.getVoices().length > 0) {
// 使用第一个可用语音进行文本转语音(澳洲本地女声)
String firstVoiceId = "21m00Tcm4TlvDq8ikWAM";
textToSpeech(inputText, firstVoiceId, outputFile,httpClient);
}
// // 获取可用语音
// VoicesResponse voicesResponse = getVoices(httpClient);
// if (voicesResponse != null && voicesResponse.getVoices() != null
// && voicesResponse.getVoices().length > 0) {
//
// }
// 使用第一个可用语音进行文本转语音(澳洲本地女声)
String firstVoiceId = "21m00Tcm4TlvDq8ikWAM";
textToSpeech(inputText, firstVoiceId, outputFile,httpClient);
} catch (IOException e) {
e.printStackTrace();
} finally {

View File

@@ -14,10 +14,13 @@ public class VoiceSettings {
private double similarity_boost;
public VoiceSettings(double stability, double similarity_boost, double speed) {
private double start_time;
public VoiceSettings(double stability, double similarity_boost, double speed,double start_time) {
this.stability = stability;
this.similarity_boost = similarity_boost;
this.speed = speed;
this.start_time = start_time;
}
// getter方法