mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-05-06 03:00:23 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc6ee1306f |
@@ -1,36 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs;
|
||||
|
||||
import net.andrewcpu.elevenlabs.api.impl.*;
|
||||
import net.andrewcpu.elevenlabs.enums.GeneratedAudioOutputFormat;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.history.History;
|
||||
import net.andrewcpu.elevenlabs.model.history.HistoryItem;
|
||||
import net.andrewcpu.elevenlabs.model.projects.Project;
|
||||
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
|
||||
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
||||
import net.andrewcpu.elevenlabs.model.response.GenerationTypeModel;
|
||||
import net.andrewcpu.elevenlabs.model.response.ProjectsModelResponse;
|
||||
import net.andrewcpu.elevenlabs.model.user.Subscription;
|
||||
import net.andrewcpu.elevenlabs.model.user.User;
|
||||
import net.andrewcpu.elevenlabs.model.voice.Voice;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.ElevenLabsRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.history.*;
|
||||
import net.andrewcpu.elevenlabs.requests.models.GetModelsRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.projects.GetProjectsRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.samples.DeleteSampleRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.samples.GetSampleRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechStreamedRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.user.GetSubscriptionRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.user.GetUserRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.voices.*;
|
||||
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ElevenLabs {
|
||||
private static String API_KEY = null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package net.andrewcpu.elevenlabs.enums;
|
||||
|
||||
public enum HttpRequestType {
|
||||
POST, GET, PUT, DELETE;
|
||||
POST, GET, PUT, DELETE
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.andrewcpu.elevenlabs.model.request;
|
||||
import net.andrewcpu.elevenlabs.enums.ProjectOutputQuality;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.invoke.StringConcatFactory;
|
||||
|
||||
public class AddProjectRequest {
|
||||
private String name;
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.andrewcpu.elevenlabs.model.request;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
import javax.management.loading.PrivateClassLoader;
|
||||
import java.io.File;
|
||||
|
||||
public class CreateAudioNativeProjectRequest extends ElevenModel {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs.model.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
import net.andrewcpu.elevenlabs.model.Language;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs.model.tuning;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ import java.util.Map;
|
||||
import static net.andrewcpu.elevenlabs.util.ElevenNetworkUtil.buildQueryParameters;
|
||||
|
||||
public abstract class ElevenLabsRequest<T> {
|
||||
private HttpRequestType type;
|
||||
private String endpoint;
|
||||
private Class<T> responseClass;
|
||||
private final HttpRequestType type;
|
||||
private final String endpoint;
|
||||
private final Class<T> responseClass;
|
||||
|
||||
public ElevenLabsRequest(HttpRequestType type, String endpoint, Class<T> clazz) {
|
||||
this.type = type;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostCreateAudioNativeProjectRequest extends PostRequest<CreateAudioEnabledProjectModelResponse> {
|
||||
private CreateAudioNativeProjectRequest request;
|
||||
private final CreateAudioNativeProjectRequest request;
|
||||
public PostCreateAudioNativeProjectRequest(CreateAudioNativeProjectRequest request) {
|
||||
super("v1/audio-native", CreateAudioEnabledProjectModelResponse.class);
|
||||
this.request = request;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PostDownloadHistoryItemsRequest extends PostRequest<File> {
|
||||
private String[] historyItemIds;
|
||||
private final String[] historyItemIds;
|
||||
public PostDownloadHistoryItemsRequest(String... historyItemIds) {
|
||||
super("v1/history/download", File.class);
|
||||
this.historyItemIds = historyItemIds;
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.andrewcpu.elevenlabs.requests.projects;
|
||||
import net.andrewcpu.elevenlabs.model.response.ProjectsModelResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GetProjectsRequest extends GetRequest<ProjectsModelResponse> {
|
||||
public GetProjectsRequest() {
|
||||
super("v1/projects", ProjectsModelResponse.class);
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostAddProjectRequest extends PostRequest<ProjectModelResponse> {
|
||||
private AddProjectRequest request;
|
||||
private final AddProjectRequest request;
|
||||
public PostAddProjectRequest(AddProjectRequest request) {
|
||||
super("v1/projects/add", ProjectModelResponse.class);
|
||||
this.request = request;
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostSpeechToSpeechRequest extends PostRequest<File> {
|
||||
private StreamLatencyOptimization latencyOptimization;
|
||||
private String modelId;
|
||||
private VoiceSettings voiceSettings;
|
||||
private File audio;
|
||||
private final StreamLatencyOptimization latencyOptimization;
|
||||
private final String modelId;
|
||||
private final VoiceSettings voiceSettings;
|
||||
private final File audio;
|
||||
public PostSpeechToSpeechRequest(String voiceId, VoiceSettings voiceSettings, File audio, String modelId, StreamLatencyOptimization latencyOptimization) {
|
||||
super("v1/speech-to-speech/" + voiceId, File.class);
|
||||
this.latencyOptimization = latencyOptimization;
|
||||
|
||||
@@ -10,10 +10,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostSpeechToSpeechStreamedRequest extends PostRequest<InputStream> {
|
||||
private StreamLatencyOptimization latencyOptimization;
|
||||
private String modelId;
|
||||
private VoiceSettings voiceSettings;
|
||||
private File audio;
|
||||
private final StreamLatencyOptimization latencyOptimization;
|
||||
private final String modelId;
|
||||
private final VoiceSettings voiceSettings;
|
||||
private final File audio;
|
||||
public PostSpeechToSpeechStreamedRequest(String voiceId, VoiceSettings voiceSettings, File audio, String modelId, StreamLatencyOptimization latencyOptimization) {
|
||||
super("v1/speech-to-speech/" + voiceId + "/stream", InputStream.class);
|
||||
this.latencyOptimization = latencyOptimization;
|
||||
|
||||
@@ -10,9 +10,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostTextToSpeechRequest extends PostRequest<File> {
|
||||
private TextToSpeechRequest request;
|
||||
private StreamLatencyOptimization streamLatencyOptimization;
|
||||
private GeneratedAudioOutputFormat outputFormat;
|
||||
private final TextToSpeechRequest request;
|
||||
private final StreamLatencyOptimization streamLatencyOptimization;
|
||||
private final GeneratedAudioOutputFormat outputFormat;
|
||||
|
||||
public PostTextToSpeechRequest(String voiceId, TextToSpeechRequest request) {
|
||||
super("v1/text-to-speech/" + voiceId, File.class);
|
||||
|
||||
@@ -5,15 +5,14 @@ import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostTextToSpeechStreamedRequest extends PostRequest<InputStream> {
|
||||
private TextToSpeechRequest request;
|
||||
private StreamLatencyOptimization streamLatencyOptimization;
|
||||
private GeneratedAudioOutputFormat outputFormat;
|
||||
private final TextToSpeechRequest request;
|
||||
private final StreamLatencyOptimization streamLatencyOptimization;
|
||||
private final GeneratedAudioOutputFormat outputFormat;
|
||||
|
||||
public PostTextToSpeechStreamedRequest(String voiceId, TextToSpeechRequest request) {
|
||||
super("v1/text-to-speech/" + voiceId, InputStream.class);
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GetVoiceRequest extends GetRequest<Voice> {
|
||||
private boolean withSettings;
|
||||
private final boolean withSettings;
|
||||
public GetVoiceRequest(String voiceId) {
|
||||
this(voiceId, true);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostAddVoiceRequest extends PostRequest<CreateVoiceResponse> {
|
||||
private String name;
|
||||
private File[] samples;
|
||||
private String description;
|
||||
private Map<String, String> labels;
|
||||
private final String name;
|
||||
private final File[] samples;
|
||||
private final String description;
|
||||
private final Map<String, String> labels;
|
||||
public PostAddVoiceRequest(String name, File[] samples, String description, Map<String, String> labels) {
|
||||
super("v1/voices/add", CreateVoiceResponse.class);
|
||||
this.name = name;
|
||||
|
||||
@@ -7,10 +7,10 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostEditVoiceRequest extends PostRequest<String> {
|
||||
private String name;
|
||||
private File[] samples;
|
||||
private String description;
|
||||
private Map<String, String> labels;
|
||||
private final String name;
|
||||
private final File[] samples;
|
||||
private final String description;
|
||||
private final Map<String, String> labels;
|
||||
public PostEditVoiceRequest(String voiceId, String name, File[] samples, String description, Map<String, String> labels) {
|
||||
super("v1/voices/" + voiceId + "/edit", String.class);
|
||||
this.name = name;
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
public class PostEditVoiceSettingsRequest extends PostRequest<String> {
|
||||
private VoiceSettings voiceSettings;
|
||||
private final VoiceSettings voiceSettings;
|
||||
public PostEditVoiceSettingsRequest(String voiceId, VoiceSettings voiceSettings) {
|
||||
super("v1/voices/" + voiceId + "/settings/edit", String.class);
|
||||
this.voiceSettings = voiceSettings;
|
||||
|
||||
@@ -12,16 +12,19 @@ import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
|
||||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.core5.http.*;
|
||||
import org.apache.hc.core5.http.ContentType;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpRequest;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.io.entity.StringEntity;
|
||||
import org.apache.hc.core5.http.message.BasicNameValuePair;
|
||||
import org.apache.hc.core5.net.URIBuilder;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -47,11 +50,7 @@ public class ElevenNetworkUtil {
|
||||
}
|
||||
|
||||
private static String encodeValue(String value) {
|
||||
try {
|
||||
return URLEncoder.encode(value, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("Encoding not supported", e);
|
||||
}
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static HttpUriRequestBase getRequest(HttpRequestType type, String path) {
|
||||
|
||||
@@ -4,8 +4,7 @@ import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class UserTest extends ElevenLabsTest {
|
||||
@Test
|
||||
@@ -14,7 +13,7 @@ public class UserTest extends ElevenLabsTest {
|
||||
ElevenLabs.getUserAPI().getUser();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertTrue("Failed to get user: " + e.getMessage(), false);
|
||||
fail("Failed to get user: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +23,7 @@ public class UserTest extends ElevenLabsTest {
|
||||
ElevenLabs.getUserAPI().getSubscription();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertFalse("Failed to get subscription: " + e.getMessage(), true);
|
||||
fail("Failed to get subscription: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class VoiceTest extends ElevenLabsTest {
|
||||
@@ -25,9 +24,9 @@ public class VoiceTest extends ElevenLabsTest {
|
||||
voice = ElevenLabs.getVoiceAPI().getVoice(ElevenLabsTest.TEST_VOICE, true);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
assertTrue("Failed to get voice: " + e.getMessage(), voice != null);
|
||||
assertNotNull("Failed to get voice: " + e.getMessage(), voice);
|
||||
}
|
||||
assertTrue(voice.getSettings() != null);
|
||||
assertNotNull(voice.getSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -37,9 +36,9 @@ public class VoiceTest extends ElevenLabsTest {
|
||||
voice = ElevenLabs.getVoiceAPI().getVoice(ElevenLabsTest.TEST_VOICE, false);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
assertTrue("Failed to get voice: " + e.getMessage(), voice != null);
|
||||
assertNotNull("Failed to get voice: " + e.getMessage(), voice);
|
||||
}
|
||||
assertTrue(voice.getSettings() == null);
|
||||
assertNull(voice.getSettings());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -49,7 +48,7 @@ public class VoiceTest extends ElevenLabsTest {
|
||||
settings = ElevenLabs.getVoiceAPI().getVoiceSettings(ElevenLabsTest.TEST_VOICE);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertTrue("Failed to get voice settings: " + e.getMessage(), false);
|
||||
fail("Failed to get voice settings: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +59,7 @@ public class VoiceTest extends ElevenLabsTest {
|
||||
defaultVoiceSettings = ElevenLabs.getVoiceAPI().getDefaultVoiceSettings();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
assertTrue("Failed to get default voice settings: " + e.getMessage(), false);
|
||||
fail("Failed to get default voice settings: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +69,8 @@ public class VoiceTest extends ElevenLabsTest {
|
||||
try{
|
||||
voices = ElevenLabs.getVoiceAPI().getVoices();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();;
|
||||
assertTrue("Failed to get voices: " + e.getMessage(), false);
|
||||
e.printStackTrace();
|
||||
fail("Failed to get voices: " + e.getMessage());
|
||||
}
|
||||
assertTrue(voices != null && voices.size() > 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user