语音优化
This commit is contained in:
@@ -38,7 +38,7 @@ public class AiCommonController extends BaseController
|
|||||||
@GetMapping("/handleTextToVice")
|
@GetMapping("/handleTextToVice")
|
||||||
public AjaxResult handleTextToVice()
|
public AjaxResult handleTextToVice()
|
||||||
{
|
{
|
||||||
elevenLabsClient.handleTextToVoice("我只是测试的文本转换成语音","/Users/wangxiangshun/Desktop/临时文件/output.mp3");
|
elevenLabsClient.handleTextToVoice("我只是测试的文本转换成语音","/Users/wangxiangshun/Desktop/临时文件/output1112.mp3");
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ whisper:
|
|||||||
chatGpt:
|
chatGpt:
|
||||||
apiKey: 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
|
apiKey: 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
|
||||||
apiUrl: https://api.openai.com/v1/chat/completions
|
apiUrl: https://api.openai.com/v1/chat/completions
|
||||||
model: gpt-3.5-turbo
|
model: gpt-4
|
||||||
role: user
|
role: user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ whisper:
|
|||||||
chatGpt:
|
chatGpt:
|
||||||
apiKey: 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
|
apiKey: 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
|
||||||
apiUrl: https://api.openai.com/v1/chat/completions
|
apiUrl: https://api.openai.com/v1/chat/completions
|
||||||
model: gpt-3.5-turbo
|
model: gpt-4
|
||||||
role: user
|
role: user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ whisper:
|
|||||||
chatGpt:
|
chatGpt:
|
||||||
apiKey: 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
|
apiKey: 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
|
||||||
apiUrl: https://api.openai.com/v1/chat/completions
|
apiUrl: https://api.openai.com/v1/chat/completions
|
||||||
model: gpt-3.5-turbo
|
model: gpt-4
|
||||||
role: user
|
role: user
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ElevenLabsClient {
|
|||||||
Map<String, Object> payload = new HashMap<>();
|
Map<String, Object> payload = new HashMap<>();
|
||||||
payload.put("text", text);
|
payload.put("text", text);
|
||||||
payload.put("model_id", modelId);
|
payload.put("model_id", modelId);
|
||||||
payload.put("voice_settings", new VoiceSettings(0.7, 0.5));
|
payload.put("voice_settings", new VoiceSettings(0.8, 0.5,1));
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
StringEntity entity = new StringEntity(gson.toJson(payload), ContentType.APPLICATION_JSON);
|
StringEntity entity = new StringEntity(gson.toJson(payload), ContentType.APPLICATION_JSON);
|
||||||
httpPost.setEntity(entity);
|
httpPost.setEntity(entity);
|
||||||
@@ -107,7 +107,8 @@ public class ElevenLabsClient {
|
|||||||
if (voicesResponse != null && voicesResponse.getVoices() != null
|
if (voicesResponse != null && voicesResponse.getVoices() != null
|
||||||
&& voicesResponse.getVoices().length > 0) {
|
&& voicesResponse.getVoices().length > 0) {
|
||||||
// 使用第一个可用语音进行文本转语音
|
// 使用第一个可用语音进行文本转语音
|
||||||
String firstVoiceId = voicesResponse.getVoices()[0].getVoice_id();
|
// String firstVoiceId = voicesResponse.getVoices()[0].getVoice_id();
|
||||||
|
String firstVoiceId = "21m00Tcm4TlvDq8ikWAM";
|
||||||
textToSpeech(inputText, firstVoiceId, outputFile,httpClient);
|
textToSpeech(inputText, firstVoiceId, outputFile,httpClient);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -5,12 +5,19 @@ package com.vetti.common.ai.elevenLabs.vo;
|
|||||||
*/
|
*/
|
||||||
public class VoiceSettings {
|
public class VoiceSettings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置语速
|
||||||
|
*/
|
||||||
|
private double speed;
|
||||||
|
// 可选:其他语音配置(如稳定性stability、相似度boost,默认无需设置)
|
||||||
private double stability;
|
private double stability;
|
||||||
|
|
||||||
private double similarity_boost;
|
private double similarity_boost;
|
||||||
|
|
||||||
public VoiceSettings(double stability, double similarity_boost) {
|
public VoiceSettings(double stability, double similarity_boost, double speed) {
|
||||||
this.stability = stability;
|
this.stability = stability;
|
||||||
this.similarity_boost = similarity_boost;
|
this.similarity_boost = similarity_boost;
|
||||||
|
this.speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getter方法
|
// getter方法
|
||||||
@@ -22,4 +29,6 @@ public class VoiceSettings {
|
|||||||
return similarity_boost;
|
return similarity_boost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getSpeed() { return speed; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user