mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-05-06 03:00:23 -04:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8630ceeb0 | ||
|
|
7593f3a3f1 | ||
|
|
5288fde44e | ||
|
|
ce86914f71 | ||
|
|
4a212c7721 | ||
|
|
f46bb6878e |
@@ -3,10 +3,7 @@
|
||||
|
||||
## Getting Started
|
||||
So you wanna make custom voices, huh? Well you've come to the right place.
|
||||
|
||||
### Note: This repo is undergoing an upgrade to v2.0
|
||||
If any of the documentation is out of place or issues occur, please submit a PR or create an issue.
|
||||
I downgraded the repo from JDK 17 to JDK 11 as well.
|
||||
This library should cover all the ElevenLabs API endpoints as of 11/15/23.
|
||||
|
||||
### Installation
|
||||
**Maven**
|
||||
@@ -19,9 +16,6 @@ To add `elevenlabs-api` to your Maven project, use:
|
||||
<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/)
|
||||
|
||||
|
||||
**JAR**
|
||||
|
||||
Compiled JARs are available via the [Releases tab](https://github.com/AndrewCPU/elevenlabs-api/releases)
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -60,7 +60,7 @@
|
||||
|
||||
<groupId>net.andrewcpu</groupId>
|
||||
<artifactId>elevenlabs-api</artifactId>
|
||||
<version>2.7.3-SNAPSHOT</version>
|
||||
<version>2.7.6-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
@@ -131,6 +132,10 @@ public class HistoryItem extends ElevenModel {
|
||||
return ElevenLabs.getHistoryAPI().getHistoryItemAudio(historyItemId);
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return ElevenNetworkUtil.getHistoryItemUrl(historyItemId);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -37,6 +37,4 @@ public abstract class ElevenLabsRequest<T> {
|
||||
}
|
||||
|
||||
public abstract Object getPayload();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class PostMultipartRequest<T> extends PostRequest<T> {
|
||||
public PostMultipartRequest(String endpoint, Class<T> clazz) {
|
||||
super(endpoint, clazz);
|
||||
}
|
||||
|
||||
|
||||
public abstract Map<String, Object> getMultipartParts(Map<String, Object> map);
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return getMultipartParts(new HashMap<>());
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,9 @@ public abstract class PostRequest<T> extends ElevenLabsRequest<T> {
|
||||
public PostRequest(String endpoint, Class<T> clazz) {
|
||||
super(HttpRequestType.POST, endpoint, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package net.andrewcpu.elevenlabs.requests.audionative;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.request.CreateAudioNativeProjectRequest;
|
||||
import net.andrewcpu.elevenlabs.model.response.CreateAudioEnabledProjectModelResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostCreateAudioNativeProjectRequest extends PostRequest<CreateAudioEnabledProjectModelResponse> {
|
||||
public class PostCreateAudioNativeProjectRequest extends PostMultipartRequest<CreateAudioEnabledProjectModelResponse> {
|
||||
private final CreateAudioNativeProjectRequest request;
|
||||
public PostCreateAudioNativeProjectRequest(CreateAudioNativeProjectRequest request) {
|
||||
super("v1/audio-native", CreateAudioEnabledProjectModelResponse.class);
|
||||
@@ -15,8 +16,7 @@ public class PostCreateAudioNativeProjectRequest extends PostRequest<CreateAudio
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> payload) {
|
||||
payload.put("name", request.getName());
|
||||
payload.put("image", request.getImage());
|
||||
payload.put("author", request.getAuthor());
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.andrewcpu.elevenlabs.requests.projects;
|
||||
import net.andrewcpu.elevenlabs.requests.DeleteRequest;
|
||||
|
||||
public class DeleteChapterByIdRequest extends DeleteRequest<String> {
|
||||
|
||||
public DeleteChapterByIdRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId, String.class);
|
||||
}
|
||||
|
||||
@@ -7,5 +7,4 @@ public class GetChapterSnapshotsRequest extends GetRequest<ChapterSnapshotsModel
|
||||
public GetChapterSnapshotsRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/snapshots", ChapterSnapshotsModelResponse.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package net.andrewcpu.elevenlabs.requests.projects;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.request.AddProjectRequest;
|
||||
import net.andrewcpu.elevenlabs.model.response.ProjectModelResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostAddProjectRequest extends PostRequest<ProjectModelResponse> {
|
||||
public class PostAddProjectRequest extends PostMultipartRequest<ProjectModelResponse> {
|
||||
private final AddProjectRequest request;
|
||||
public PostAddProjectRequest(AddProjectRequest request) {
|
||||
super("v1/projects/add", ProjectModelResponse.class);
|
||||
@@ -15,8 +16,7 @@ public class PostAddProjectRequest extends PostRequest<ProjectModelResponse> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> payload) {
|
||||
payload.put("name",request.getName());
|
||||
payload.put("from_url", request.getFromUrl());
|
||||
payload.put("from_document", request.getFromDocument());
|
||||
|
||||
@@ -6,9 +6,4 @@ public class PostConvertChapterRequest extends PostRequest<String> {
|
||||
public PostConvertChapterRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/convert", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,4 @@ public class PostConvertProjectRequest extends PostRequest<String> {
|
||||
public PostConvertProjectRequest(String projectId) {
|
||||
super("v1/projects/" + projectId + "/convert", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ public class PostStreamChapterSnapshotAudioRequest extends PostRequest<InputStre
|
||||
public PostStreamChapterSnapshotAudioRequest(String projectId, String chapterId, String chapterSnapshotId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/snapshots/" + chapterSnapshotId + "/stream", InputStream.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ public class PostStreamProjectSnapshotAudioRequest extends PostRequest<InputStre
|
||||
public PostStreamProjectSnapshotAudioRequest(String projectId, String snapshotId) {
|
||||
super("v1/projects/" + projectId + "/snapshots/" + snapshotId + "/stream", InputStream.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.requests.sts;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
@@ -31,9 +33,15 @@ public class PostSpeechToSpeechRequest extends PostRequest<File> {
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
String voiceSettingsString;
|
||||
try {
|
||||
voiceSettingsString = new ObjectMapper().writeValueAsString(voiceSettings);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
body.put("audio", audio);
|
||||
body.put("model_id", modelId);
|
||||
body.put("voice_settings", voiceSettings);
|
||||
body.put("voice_settings", voiceSettingsString);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.requests.sts;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
@@ -32,9 +34,15 @@ public class PostSpeechToSpeechStreamedRequest extends PostRequest<InputStream>
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
String voiceSettingsString;
|
||||
try {
|
||||
voiceSettingsString = new ObjectMapper().writeValueAsString(voiceSettings);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
body.put("audio", audio);
|
||||
body.put("model_id", modelId);
|
||||
body.put("voice_settings", voiceSettings);
|
||||
body.put("voice_settings", voiceSettingsString);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,4 @@ public class GetVoiceRequest extends GetRequest<Voice> {
|
||||
payload.put("with_settings", String.valueOf(withSettings));
|
||||
return payload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.andrewcpu.elevenlabs.requests.voices;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostAddVoiceRequest extends PostRequest<CreateVoiceResponse> {
|
||||
public class PostAddVoiceRequest extends PostMultipartRequest<CreateVoiceResponse> {
|
||||
private final String name;
|
||||
private final File[] samples;
|
||||
private final String description;
|
||||
@@ -37,8 +38,7 @@ public class PostAddVoiceRequest extends PostRequest<CreateVoiceResponse> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> map) {
|
||||
map.put("name", this.name);
|
||||
map.put("files", this.samples);
|
||||
map.put("description", this.description);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.andrewcpu.elevenlabs.requests.voices;
|
||||
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostEditVoiceRequest extends PostRequest<String> {
|
||||
public class PostEditVoiceRequest extends PostMultipartRequest<String> {
|
||||
private final String name;
|
||||
private final File[] samples;
|
||||
private final String description;
|
||||
@@ -36,8 +37,7 @@ public class PostEditVoiceRequest extends PostRequest<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> map) {
|
||||
map.put("name", this.name);
|
||||
map.put("files", this.samples);
|
||||
map.put("description", this.description);
|
||||
|
||||
@@ -137,6 +137,10 @@ public class ElevenNetworkUtil {
|
||||
return request;
|
||||
}
|
||||
|
||||
public static String getHistoryItemUrl(String historyItemId) {
|
||||
return BASE_URL + "v1/history/" + historyItemId + "/audio";
|
||||
}
|
||||
|
||||
public static <T> T sendRequest(HttpRequestType method, String path, Object payload, Class<T> responseType) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
path = BASE_URL + path;
|
||||
|
||||
Reference in New Issue
Block a user