8 Commits
v58 ... v61

Author SHA1 Message Date
Andrew Stein
81cdf05152 Reduced unneeded code bloat 2023-11-15 18:28:08 -05:00
Andrew Stein
6e5ae633a6 Updated POM version. 2023-11-15 18:09:57 -05:00
Andrew Stein
a6163fd67f Improved getEndpoint() changes of query parameter handling. 2023-11-15 18:09:41 -05:00
Andrew Stein
26a4ab1fa4 Removed former query parameter implementation in ElevenNetworkUtil class. (It has since been replaced by ElevenLabsRequest changes) 2023-11-15 18:09:25 -05:00
Andrew Stein
72f35c14b7 Fixed inconsistency with new getQueryParameters() inherited function. 2023-11-15 18:08:01 -05:00
Andrew Stein
90a092aa81 Fixed bug in output format. (Should've been lower case) 2023-11-15 18:07:34 -05:00
Andrew Stein
02d7ec0685 Added default model setting in ElevenLabs 2023-11-15 18:07:16 -05:00
Andrew Stein
75f1c40f59 Updating Jackson version to remove vulnerability warnings. 2023-11-15 17:49:49 -05:00
32 changed files with 59 additions and 143 deletions

View File

@@ -16,7 +16,7 @@ To add `elevenlabs-api` to your Maven project, use:
<dependency>
<groupId>net.andrewcpu</groupId>
<artifactId>elevenlabs-api</artifactId>
<version>2.7</version>
<version>2.7.2</version>
</dependency>
```
The most up-to date package information can be found on the [Packages tab](https://github.com/AndrewCPU/elevenlabs-api/packages/)
@@ -32,6 +32,9 @@ To access your ElevenLabs API key, head to the [official website](https://eleven
To set up your ElevenLabs API key, you must register it with the ElevenLabsAPI Java API like below:
```java
ElevenLabs.setApiKey("YOUR_API_KEY_HERE");
ElevenLabs.setDefaultModel("eleven_monolingual_v1"); // Optional, defaults to: "eleven_monolingual_v1"
```
*For any public repository security, you should store your API key in an environment variable, or external from your source code.*
@@ -420,6 +423,11 @@ If you like what you see, give it a star! :)
- - -
## Todo
I will probably rework the 2 new builders I added when I added projects support. Their usage should be more clear, though the documentation covers their use cases I believe.
- - -
#### Unit Testing
Unit tests have been created, these endpoints are destructive and not included in the testing:
* deleteHistoryItem - WONT TEST

View File

@@ -60,7 +60,7 @@
<groupId>net.andrewcpu</groupId>
<artifactId>elevenlabs-api</artifactId>
<version>2.7</version>
<version>2.7.3-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
@@ -80,17 +80,17 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.4.1</version>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.4</version>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.4</version>
<version>2.15.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -194,7 +194,6 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,5 +1,6 @@
package net.andrewcpu.elevenlabs;
import com.fasterxml.jackson.annotation.JsonIgnore;
import net.andrewcpu.elevenlabs.api.impl.*;
public class ElevenLabs {
@@ -17,6 +18,15 @@ public class ElevenLabs {
public static String getApiKey() {
return API_KEY;
}
private static String defaultModel = "eleven_monolingual_v1";
public static String getDefaultModel() {
return defaultModel;
}
public static void setDefaultModel(String defaultModel) {
ElevenLabs.defaultModel = defaultModel;
}
public static void setApiKey(String apiKey) {
API_KEY = apiKey;

View File

@@ -167,28 +167,28 @@ public class Voice extends ElevenModel {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId,text, model, outputFormat,StreamLatencyOptimization.getDefault(), settings);
}
public File generate(String text, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,StreamLatencyOptimization.getDefault(), settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), outputFormat,StreamLatencyOptimization.getDefault(), settings);
}
public File generate(String text, VoiceSettings settings, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(),streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(),streamLatencyOptimization, settings);
}
public File generate(String text, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), outputFormat,streamLatencyOptimization, settings);
}
public File generate(String text, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), outputFormat,streamLatencyOptimization, settings);
}
public File generate(String text, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
}
public File generate(String text, VoiceSettings settings) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), settings);
}
public File generate(String text) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), settings);
}
@@ -202,11 +202,11 @@ public class Voice extends ElevenModel {
}
public InputStream generateStream(String text, VoiceSettings settings) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), settings);
}
public InputStream generateStream(String text) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), settings);
}
public InputStream generateStream(String text, String model, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
@@ -218,11 +218,11 @@ public class Voice extends ElevenModel {
}
public InputStream generateStream(String text, VoiceSettings settings, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", generatedAudioOutputFormat, streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), generatedAudioOutputFormat, streamLatencyOptimization, settings);
}
public InputStream generateStream(String text, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", generatedAudioOutputFormat, streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), generatedAudioOutputFormat, streamLatencyOptimization, settings);
}
public InputStream generateStream(String text, String model, StreamLatencyOptimization streamLatencyOptimization) {
@@ -234,11 +234,11 @@ public class Voice extends ElevenModel {
}
public InputStream generateStream(String text, VoiceSettings settings, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
}
public InputStream generateStream(String text, StreamLatencyOptimization streamLatencyOptimization) {
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
}
public File speechToSpeech(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId, VoiceSettings voiceSettings) {

View File

@@ -6,4 +6,9 @@ public abstract class DeleteRequest<T> extends ElevenLabsRequest<T> {
public DeleteRequest(String endpoint, Class<T> clazz) {
super(HttpRequestType.DELETE, endpoint, clazz);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -23,6 +23,8 @@ public abstract class ElevenLabsRequest<T> {
}
public String getEndpoint() {
Map<String, String> params = getQueryParameters();
if(params.isEmpty()) return endpoint;
return endpoint + "?" + buildQueryParameters(getQueryParameters());
}

View File

@@ -6,4 +6,9 @@ public abstract class GetRequest<T> extends ElevenLabsRequest<T> {
public GetRequest(String endpoint, Class<T> clazz) {
super(HttpRequestType.GET, endpoint, clazz);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -6,9 +6,4 @@ public class DeleteHistoryItemRequest extends DeleteRequest<String> {
public DeleteHistoryItemRequest(String historyItemId) {
super("v1/history/" + historyItemId, String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -8,9 +8,4 @@ public class GetHistoryItemAudioRequest extends GetRequest<File> {
public GetHistoryItemAudioRequest(String historyItemId) {
super("v1/history/" + historyItemId + "/audio", File.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetHistoryItemByIdRequest extends GetRequest<HistoryItem> {
public GetHistoryItemByIdRequest(String historyId) {
super("v1/history/" + historyId, HistoryItem.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetHistoryRequest extends GetRequest<History> {
public GetHistoryRequest() {
super("v1/history", History.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetModelsRequest extends GetRequest<GenerationTypeModel[]> {
public GetModelsRequest() {
super("v1/models", GenerationTypeModel[].class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class DeleteChapterByIdRequest extends DeleteRequest<String> {
public DeleteChapterByIdRequest(String projectId, String chapterId) {
super("v1/projects/" + projectId + "/chapters/" + chapterId, String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -6,9 +6,4 @@ public class DeleteProjectByIdRequest extends DeleteRequest<String> {
public DeleteProjectByIdRequest(String projectId) {
super("v1/projects/" + projectId, String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetChapterByIdRequest extends GetRequest<Chapter> {
public GetChapterByIdRequest(String projectId, String chapterId) {
super("v1/projects/" + projectId + "/chapters/" + chapterId, Chapter.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -8,8 +8,4 @@ public class GetChapterSnapshotsRequest extends GetRequest<ChapterSnapshotsModel
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/snapshots", ChapterSnapshotsModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetProjectByIdRequest extends GetRequest<Project> {
public GetProjectByIdRequest(String projectId) {
super("v1/projects/" + projectId, Project.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetProjectChaptersRequest extends GetRequest<ChaptersModelResponse>
public GetProjectChaptersRequest(String projectId) {
super("v1/projects/" + projectId + "/chapters", ChaptersModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetProjectSnapshotsRequest extends GetRequest<ProjectSnapshotsModel
public GetProjectSnapshotsRequest(String projectId) {
super("v1/projects/" + projectId + "/snapshots", ProjectSnapshotsModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetProjectsRequest extends GetRequest<ProjectsModelResponse> {
public GetProjectsRequest() {
super("v1/projects", ProjectsModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -6,9 +6,4 @@ public class DeleteSampleRequest extends DeleteRequest<String> {
public DeleteSampleRequest(String voiceId, String sampleId) {
super("v1/voices/" + voiceId + "/samples/" + sampleId, String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -8,9 +8,4 @@ public class GetSampleRequest extends GetRequest<File> {
public GetSampleRequest(String voiceId, String sampleId) {
super("v1/voices/" + voiceId + "/samples/" + sampleId + "/audio", File.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -52,7 +52,7 @@ public class PostTextToSpeechRequest extends PostRequest<File> {
public Map<String, String> getQueryParameters() {
Map<String, String> map = new HashMap<>();
map.put("optimize_streaming_latency", String.valueOf(streamLatencyOptimization.getValue()));
map.put("output_format", outputFormat.name());
map.put("output_format", outputFormat.name().toLowerCase());
return map;
}
}

View File

@@ -46,7 +46,7 @@ public class PostTextToSpeechStreamedRequest extends PostRequest<InputStream> {
public Map<String, String> getQueryParameters() {
Map<String, String> map = new HashMap<>();
map.put("optimize_streaming_latency", String.valueOf(streamLatencyOptimization.getValue()));
map.put("output_format", outputFormat.name());
map.put("output_format", outputFormat.name().toLowerCase());
return map;
}

View File

@@ -8,9 +8,4 @@ public class GetSubscriptionRequest extends GetRequest<Subscription> {
public GetSubscriptionRequest() {
super("v1/user/subscription", Subscription.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetUserRequest extends GetRequest<User> {
public GetUserRequest() {
super("v1/user", User.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -6,9 +6,4 @@ public class DeleteVoiceRequest extends DeleteRequest<String> {
public DeleteVoiceRequest(String voiceId) {
super("v1/voices/" + voiceId, String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetDefaultVoiceSettingsRequest extends GetRequest<VoiceSettings> {
public GetDefaultVoiceSettingsRequest() {
super("v1/voices/settings/default", VoiceSettings.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -12,15 +12,18 @@ public class GetVoiceRequest extends GetRequest<Voice> {
this(voiceId, true);
}
public GetVoiceRequest(String voiceId, boolean withSettings) {
super( "v1/voices/" + voiceId, Voice.class);
this.withSettings = withSettings;
}
@Override
public Object getPayload() {
Map<String, Object> payload = new HashMap<>();
payload.put("with_settings", withSettings);
public Map<String, String> getQueryParameters() {
Map<String, String> payload = new HashMap<>();
payload.put("with_settings", String.valueOf(withSettings));
return payload;
}
}

View File

@@ -7,9 +7,4 @@ public class GetVoiceSettingsRequest extends GetRequest<VoiceSettings> {
public GetVoiceSettingsRequest(String voiceId) {
super("v1/voices/" + voiceId + "/settings", VoiceSettings.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -7,9 +7,4 @@ public class GetVoicesRequest extends GetRequest<VoiceModelResponse> {
public GetVoicesRequest() {
super("v1/voices", VoiceModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -66,22 +66,10 @@ public class ElevenNetworkUtil {
}
}
private static List<NameValuePair> getParameters(Object payload) {
List<NameValuePair> parameters = new ArrayList<>();
if (payload instanceof Map<?, ?>) {
Map<?, ?> payloadMap = (Map<?, ?>) payload;
for (Map.Entry<?, ?> entry : payloadMap.entrySet()) {
parameters.add(new BasicNameValuePair(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())));
}
}
return parameters;
}
private static HttpUriRequestBase handleNonBodyRequest(HttpRequestType requestType, Object payload, String path) {
List<NameValuePair> parameters = getParameters(payload);
private static HttpUriRequestBase handleNonBodyRequest(HttpRequestType requestType, String path) {
HttpUriRequestBase request = getRequest(requestType, path);
try {
request.setUri(new URIBuilder(path).addParameters(parameters).build());
request.setUri(new URIBuilder(path).build());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
@@ -141,7 +129,7 @@ public class ElevenNetworkUtil {
public static HttpUriRequestBase getRequest(HttpRequestType method, String path, Object payload) throws JsonProcessingException {
HttpUriRequestBase request;
if (method == HttpRequestType.GET || method == HttpRequestType.DELETE) {
request = handleNonBodyRequest(method, payload, path);
request = handleNonBodyRequest(method, path);
} else {
request = handleBodyRequest(method, payload, path);
}