From 060ba472c7fc19bee05a38516a93ca1521a065bd Mon Sep 17 00:00:00 2001 From: wangxiangshun Date: Sun, 19 Oct 2025 09:23:08 +0800 Subject: [PATCH] =?UTF-8?q?TTS=20=E8=BF=94=E5=9B=9E=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/elevenLabs/ElevenLabsClient.java | 19 ++++++++++--------- .../ai/elevenLabs/vo/VoiceSettings.java | 5 ++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/ElevenLabsClient.java b/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/ElevenLabsClient.java index 464890a..0ca9324 100644 --- a/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/ElevenLabsClient.java +++ b/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/ElevenLabsClient.java @@ -53,7 +53,7 @@ public class ElevenLabsClient { Map 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 { diff --git a/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/vo/VoiceSettings.java b/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/vo/VoiceSettings.java index d33c698..6a7c503 100644 --- a/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/vo/VoiceSettings.java +++ b/vetti-common/src/main/java/com/vetti/common/ai/elevenLabs/vo/VoiceSettings.java @@ -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方法