#Calling the API can only generate English and cannot generate speech in other languages

1 messages · Page 1 of 1 (latest)

forest rock
#

// 创建HttpClient实例
CloseableHttpClient httpClient = HttpClients.createDefault();

        // 创建HttpPost请求对象
        HttpPost httpPost = new HttpPost("https://api.elevenlabs.io/v1/text-to-speech/CYw3kZ02Hs0563khs1Fj/stream");

        // 设置请求头
        httpPost.setHeader("Content-Type", "application/json");
        httpPost.setHeader("xi-api-key", "my key");

        // 设置请求体
        String requestBody = "{\n" +
                "  \"model_id\": \"eleven_multilingual_v2\",\n" +
                "  \"text\": \"你好,我叫小飞额,我想对接11Labs\",\n" +
                "  \"lang\": \"zh-CN\",\n" +  // 删除额外的空格
                "  \"voice_settings\": {\n" +
                "    \"similarity_boost\": 0.75,\n" +
                "    \"stability\": 0.5,\n" +
                "    \"style\": 0.0,\n" +
                "    \"use_speaker_boost\": true\n" +
                "  }\n" +
                "}";
        httpPost.setEntity(new StringEntity(requestBody));

        // 发送POST请求
        HttpResponse httpResponse = httpClient.execute(httpPost);

        // 读取响应内容
        InputStream inputStream = httpResponse.getEntity().getContent();

        // 创建文件输出流
        FileOutputStream outputStream = new FileOutputStream("E:\\dianyi\\audio\\15.mp3");

        // 使用Apache Commons IO库将输入流复制到输出流
        IOUtils.copy(inputStream, outputStream);

        // 关闭流
        inputStream.close();
        outputStream.close();

        // 关闭响应
        httpClient.close();
forest rock
#

I entered text in Chinese, but no Chinese audio was generated. Why is this

rich anvil
#

" "lang": "zh-CN",\n" + // 删除额外的空格
This is not a valid API parameter. The language of the audio is based on the models perception of the language. So if you enter chinese text it should output in Chinese..

forest rock
rich anvil
#

So you getting a response from the API but it is not in Chinese is that correct?

forest rock
rich anvil
#

But what happens when you try and generate audio with Chinese text?

forest rock
# rich anvil But what happens when you try and generate audio with Chinese text?

This is my code JAVA code,Please help me find out where the problem is. I think there is no problem with the code at all. Thank you very much.
public static void textToSpeechStream() {
try {
// 创建HttpClient实例
CloseableHttpClient httpClient = HttpClients.createDefault();
// 创建HttpPost请求对象
HttpPost httpPost = new HttpPost("https://api.elevenlabs.io/v1/text-to-speech/CYw3kZ02Hs0563khs1Fj/stream");
// 设置请求头
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("xi-api-key", "my key");
String requestBody = "{\n " +
""model_id ": "eleven_multilingual_v2",\n" +
""text": "你好,我叫小飞额,我想对接",\n" +
""voice_settings": {\n" +
""similarity_boost": 0.75,\n" +
""stability": 0.5,\n" +
""style": 0.0,\n" +
""use_speaker_boost": true\n " +
"}" +
"}";
httpPost.setEntity(new StringEntity(requestBody));
// 发送POST请求
HttpResponse httpResponse = httpClient.execute(httpPost);
// 读取响应内容
InputStream inputStream = httpResponse.getEntity().getContent();
// 创建文件输出流
FileOutputStream outputStream = new FileOutputStream("E:\dianyi\audio\16.mp3");
// 使用Apache Commons IO库将输入流复制到输出流
IOUtils.copy(inputStream, outputStream);
// 关闭流
inputStream.close();
outputStream.close();

        // 关闭响应
        httpClient.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
rich anvil
#

But what happens when you try and generate audio with Chinese text?
What is the exact issue you are getting?

#

Have you tried using a different voice?

forest rock
rich anvil
#

Look in your history and make sure the model is being passed correctly

#

Or tiry using a different voice

forest rock
forest rock
rich anvil
#

You need to provide more context.

the other languages generated were all wrong. I
What does this actually mean? Like they didn't work and you got no response form the API or you are not happy with the audio results? Can you provide samples of the audio you are refering to?

forest rock
rich anvil
#

Have you tested the same settings in the WebUI? It could be an issue with how the text is being passed to the API

#

中文:春天里弥漫着泥土的气息1232324324234535
If you have Arabic numerals in the text it will a lot of the time read them in English. It is highly reccomended that you "spell out" any numbers

forest rock
rich anvil
#

You just need to experiment with different voices until you get a result you are happy with. ElevenLabs are not offering PVC in all languages so these voices will give you the best results #announcements message