mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-01-09 12:38:03 -05:00
License defining, POM updates, bug fixes.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -39,3 +39,4 @@ build/
|
||||
|
||||
**/src/main/java/net/andrewcpu/elevenlabs/Main.java
|
||||
./src/main/java/net/andrewcpu/elevenlabs/Main.java
|
||||
Main.java
|
||||
|
||||
29
README.md
29
README.md
@@ -9,6 +9,9 @@ An unofficial ElevenLabs AI Voice Generation Java API. I am not affiliated with
|
||||
## Getting Started
|
||||
So you wanna make custom voices, huh? Well you've come to the right place.
|
||||
|
||||
### Installation
|
||||
xxx
|
||||
|
||||
### Setting up your API Key
|
||||
To access your ElevenLabs API key, head to the [official website](https://elevenlabs.io/), you can view your xi-api-key using the 'Profile' tab on the website.
|
||||
To set up your ElevenLabs API key, you must register it with the ElevenLabsAPI Java API like below:
|
||||
@@ -17,7 +20,7 @@ ElevenLabsAPI.getInstance().setAPIKey("YOUR_API_KEY_HERE");
|
||||
```
|
||||
*For any public repository security, you should store your API key in an environment variable, or external from your source code.*
|
||||
|
||||
Once you've injected your API Key, you can safely assume that you will not receive a ElevenAPINotInitiatedException.
|
||||
Once you've injected your API Key, you can safely assume that you will not receive a ElevenLabsAPINotInitiatedException.
|
||||
- - -
|
||||
|
||||
## Voices
|
||||
@@ -26,14 +29,12 @@ To retrieve your list of accessible Voices, you can statically utilize Voice#get
|
||||
```java
|
||||
List<Voice> voices = Voice.getVoices();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Accessing the Default Voice Settings
|
||||
ElevenLabs provides a default VoiceSettings configuration which can be accessed statically from VoiceSettings#getDefaultVoiceSettings() **This is a network request**.
|
||||
```
|
||||
VoiceSettings.getDefaultVoiceSettings();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Getting a Voice by ID
|
||||
Retrieving voices via their **voiceId** can be done in a few different ways.
|
||||
@@ -48,7 +49,6 @@ If you don't wish to retrieve the Voice model with it's default settings include
|
||||
```java
|
||||
Voice.get(String voiceId, boolean withSettings);
|
||||
```
|
||||
- - -
|
||||
|
||||
### Deleting a voice
|
||||
To delete a voice, you can utilize the Voice#delete() function. This will delete a voice from the ElevenLabs API.
|
||||
@@ -56,7 +56,6 @@ To delete a voice, you can utilize the Voice#delete() function. This will delete
|
||||
Voice voice;
|
||||
voice.delete();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Retrieving an Updated VoiceSettings for a Voice
|
||||
There may be times when the default VoiceSettings parameters are changed externally from the API (Via the main website or another integrated system), to retrieve and apply the most up to date VoiceSettings object to a voice, you can use the Voice#fetchSettings() function. (This is a network request, and it updates the object you're acting upon)
|
||||
@@ -64,7 +63,6 @@ There may be times when the default VoiceSettings parameters are changed externa
|
||||
Voice voice;
|
||||
voice.fetchSettings(); // requests updated settings from ElevenLabs
|
||||
```
|
||||
- - -
|
||||
|
||||
### Updating the VoiceSettings for a Voice
|
||||
A VoiceSettings object can be modified and updated in a voice.
|
||||
@@ -73,7 +71,6 @@ The Voice#updateVoiceSettings(VoiceSettings settings) function updates the **def
|
||||
Voice voice;
|
||||
voice.updateVoiceSettings(VoiceSettings settings);
|
||||
```
|
||||
- - -
|
||||
|
||||
### Editing a Voice
|
||||
To edit an existing Voice model, you can load the Voice into a VoiceBuilder with the VoiceBuilder#fromVoice(Voice voice) function.
|
||||
@@ -91,7 +88,6 @@ builder.removeLabel("oldKey");
|
||||
builder.withFile(new File("someAudioFile.mp3")); // add a new audio sample
|
||||
voice = builder.edit(); // edit voice & return updated voice object
|
||||
```
|
||||
- - -
|
||||
|
||||
### Creating a Voice
|
||||
To generate a new Voice model from the API, you can use the VoiceBuilder class to assemble the required parameters for a Voice model.
|
||||
@@ -108,7 +104,6 @@ builder.withFile(new File("sample2.mp3"));
|
||||
builder.withLabel("accent", "American");
|
||||
voice = builder.create();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Generating Audio
|
||||
To generate an Audio file with a given Voice, you can utilize the Voice#generate(...) functions.
|
||||
@@ -128,7 +123,6 @@ To access the sample(s) for a given Voice, you can utilize Voice#getSamples().
|
||||
Voice voice;
|
||||
List<Sample> samples = voice.getSamples();
|
||||
```
|
||||
- - -
|
||||
### Downloading a Sample
|
||||
You can download a Sample via the Sample#downloadAudio(File outputFile) function.
|
||||
The File parameter of downloadAudio is the location of where you want to locally download the sample.
|
||||
@@ -136,7 +130,6 @@ The File parameter of downloadAudio is the location of where you want to locally
|
||||
Voice voice;
|
||||
File file = voice.getSamples().get(0).downloadAudio(File outputFile);
|
||||
```
|
||||
- - -
|
||||
|
||||
### Deleting a Sample
|
||||
```java
|
||||
@@ -152,7 +145,6 @@ To get your ElevenLabs generation History, you can utilize History#get(). (You c
|
||||
```java
|
||||
History history = History.get();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Getting a History Item
|
||||
To retrieve a HistoryItem from your History, you can use History#getHistoryItem(String itemId).
|
||||
@@ -160,7 +152,6 @@ To retrieve a HistoryItem from your History, you can use History#getHistoryItem(
|
||||
History history;
|
||||
HistoryItem item = history.getHistoryItem("itemId");
|
||||
```
|
||||
- - -
|
||||
|
||||
### Downloading History
|
||||
The official API of ElevenLabs provides an endpoint for downloading multiple HistoryItem's as a ZIP file. To download such items, you can pass a String[] containing the HistoryItem IDs, OR you can provide a List of HistoryItems.
|
||||
@@ -170,7 +161,6 @@ History history;
|
||||
File download = history.downloadHistory(new String[]{"item-id1", "item-id2"}, new File("outputFile.zip"));
|
||||
File download = history.downloadHistory(List<HistoryItem> historyItems, File outputFile);
|
||||
```
|
||||
- - -
|
||||
|
||||
### Deleting a HistoryItem
|
||||
You can utilize the HistoryItem#delete() function to delete a HistoryItem from ElevenLabs.
|
||||
@@ -178,7 +168,6 @@ You can utilize the HistoryItem#delete() function to delete a HistoryItem from E
|
||||
HistoryItem item;
|
||||
item.delete();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Requesting the Voice for a HistoryItem
|
||||
By default, a HistoryItem contains the voiceId of the voice used to generate it. The getVoice() function will send a request to the ElevenLabs API to retrieve the voice object. (See also Voice.get() and Voice.getVoices())
|
||||
@@ -186,7 +175,6 @@ By default, a HistoryItem contains the voiceId of the voice used to generate it.
|
||||
HistoryItem item;
|
||||
Voice voice = item.getVoice();
|
||||
```
|
||||
- - -
|
||||
|
||||
### Downloading a HistoryItem Audio
|
||||
A HistoryItem is a previous TTS generation. You can download the generation as an MP3 file by providing the downloadAudio(File file) function with the target location for the downloaded file. The return value is the same File provided as a parameter.
|
||||
@@ -213,7 +201,14 @@ User user = User.get();
|
||||
|
||||
- - -
|
||||
## Exceptions
|
||||
### ElevenAPINotInitiatedException
|
||||
You'll find most actions that make network requests also will throw IOException, ElevenLabsAPINotInitiatedException, and ElevenLabsValidationException. The only function that will make a network request without throwing an exception is HistoryItem#getVoice().
|
||||
### ElevenLabsAPINotInitiatedException
|
||||
This exception will be thrown if you attempt to use the library without setting an API key.
|
||||
### ElevenLabsValidationException
|
||||
This error indicates a malformed request to the ElevenLabs API. The exception should provide the location of any syntactically incorrect parameters within the request.
|
||||
- - -
|
||||
|
||||
## Misc
|
||||
As specified on the official ElevenLabs API Documentation, their API is experimental and all endpoints are subject to change. Depending on how they modify their API, may break this library. Should you notice any API changes / library errors, feel free to submit an issue or a PR.
|
||||
|
||||
If you like what you see, give it a star! :)
|
||||
|
||||
53
pom.xml
53
pom.xml
@@ -4,6 +4,26 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<name>Unofficial Java ElevenLabs Voice API</name>
|
||||
<description>An API level interaction between Java and the ElevenLabs Voice Generation Web API.</description>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>Andrewcpu</id>
|
||||
<name>Andrew Stein</name>
|
||||
<roles>
|
||||
<role>Project Lead</role>
|
||||
</roles>
|
||||
<timezone>UTC-5</timezone>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/AndrewCPU/elevenlabs-api.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:AndrewCPU/elevenlabs-api.git</developerConnection>
|
||||
<url>https://github.com/AndrewCPU/elevenlabs-api</url>
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<groupId>net.andrewcpu</groupId>
|
||||
<artifactId>elevenlabs-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
@@ -13,6 +33,15 @@
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
@@ -20,4 +49,28 @@
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>voice-grabber-${version}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -20,7 +20,7 @@ import net.andrewcpu.elevenlabs.elements.voice.Sample;
|
||||
import net.andrewcpu.elevenlabs.elements.voice.Voice;
|
||||
import net.andrewcpu.elevenlabs.elements.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.enums.ContentType;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
|
||||
import java.io.File;
|
||||
@@ -69,104 +69,104 @@ public class ElevenLabsAPI {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public Subscription getSubscription() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public Subscription getSubscription() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (Subscription) getResult(new GetSubscriptionInfoRequest());
|
||||
}
|
||||
|
||||
public User getUser() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public User getUser() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (User) getResult(new GetUserRequest());
|
||||
}
|
||||
|
||||
public File getTextToSpeech(String text, Voice voice, VoiceSettings settings, File outputFile) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File getTextToSpeech(String text, Voice voice, VoiceSettings settings, File outputFile) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (File)getResult(new GetTextToSpeechRequest(voice, settings, text, outputFile));
|
||||
}
|
||||
|
||||
public List<Voice> getVoices() throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public List<Voice> getVoices() throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return (List<Voice>) getResult(new GetVoicesRequest());
|
||||
}
|
||||
|
||||
public Voice getVoice(String voiceId, boolean withSettings) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public Voice getVoice(String voiceId, boolean withSettings) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return (Voice)getResult(new GetVoiceRequest(voiceId, withSettings));
|
||||
}
|
||||
|
||||
public Voice getVoice(String voiceId) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public Voice getVoice(String voiceId) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return getVoice(voiceId, true);
|
||||
}
|
||||
|
||||
public VoiceSettings getVoiceSettings(String voiceId) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public VoiceSettings getVoiceSettings(String voiceId) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (VoiceSettings) getResult(new GetVoiceSettingsRequest(voiceId));
|
||||
}
|
||||
|
||||
public VoiceSettings getVoiceSettings(Voice voice) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public VoiceSettings getVoiceSettings(Voice voice) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return getVoiceSettings(voice.getVoiceId());
|
||||
}
|
||||
|
||||
public String deleteVoice(Voice voice) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteVoice(Voice voice) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return deleteVoice(voice.getVoiceId());
|
||||
}
|
||||
|
||||
public String deleteVoice(String voiceId) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteVoice(String voiceId) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (String)getResult(new DeleteVoiceRequest(voiceId));
|
||||
}
|
||||
|
||||
public String editVoice(Voice voice, VoiceSettings voiceSettings) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String editVoice(Voice voice, VoiceSettings voiceSettings) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return editVoice(voice.getVoiceId(), voiceSettings);
|
||||
}
|
||||
|
||||
public String editVoice(String voiceId, VoiceSettings settings) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String editVoice(String voiceId, VoiceSettings settings) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (String)getResult(new UpdateVoiceSettingsRequest(voiceId, settings));
|
||||
}
|
||||
|
||||
|
||||
public String deleteSample(String voiceId, String sampleId) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteSample(String voiceId, String sampleId) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (String)getResult(new DeleteSampleRequest(voiceId, sampleId));
|
||||
}
|
||||
|
||||
public String deleteSample(Voice voice, String sampleId) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteSample(Voice voice, String sampleId) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return deleteSample(voice.getVoiceId(), sampleId);
|
||||
}
|
||||
public String deleteSample(String voiceId, Sample sample) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteSample(String voiceId, Sample sample) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return deleteSample(voiceId, sample.getSampleId());
|
||||
}
|
||||
|
||||
public String deleteSample(Voice voice, Sample sample) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteSample(Voice voice, Sample sample) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return deleteSample(voice.getVoiceId(), sample.getSampleId());
|
||||
}
|
||||
|
||||
public File getSampleAudio(String voiceId, String sampleId, File file) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File getSampleAudio(String voiceId, String sampleId, File file) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (File)getResult(new GetAudioSampleRequest(voiceId, sampleId, file));
|
||||
}
|
||||
public File getSampleAudio(Voice voice, Sample sample, File file) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File getSampleAudio(Voice voice, Sample sample, File file) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return getSampleAudio(voice.getVoiceId(), sample.getSampleId(), file);
|
||||
}
|
||||
|
||||
public History getHistory() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public History getHistory() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (History)getResult(new GetHistoryRequest());
|
||||
}
|
||||
|
||||
public File downloadHistory(List<String> historyIds, File outputFile) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File downloadHistory(List<String> historyIds, File outputFile) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (File)getResult(new DownloadHistoryRequest(historyIds, outputFile));
|
||||
}
|
||||
|
||||
public File getHistoryItemAudio(History.HistoryItem historyItem, File outputFile) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File getHistoryItemAudio(History.HistoryItem historyItem, File outputFile) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (File)getResult(new GetHistoryAudioRequest(historyItem.getHistoryItemId(), outputFile));
|
||||
}
|
||||
|
||||
public String deleteHistoryItem(History.HistoryItem historyItem) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String deleteHistoryItem(History.HistoryItem historyItem) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (String)getResult(new DeleteHistoryItemRequest(historyItem.getHistoryItemId()));
|
||||
}
|
||||
|
||||
public VoiceSettings getDefaultVoiceSettings() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public VoiceSettings getDefaultVoiceSettings() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return (VoiceSettings)getResult(new GetDefaultVoiceSettingsRequest());
|
||||
}
|
||||
|
||||
public String createVoice(String name, Map<String, String> labels, List<File> files) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public String createVoice(String name, Map<String, String> labels, List<File> files) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
CreateVoiceRequest request = new CreateVoiceRequest(name, files, labels);
|
||||
return (String)(getResult(request));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public String editVoice(String voiceId, String name, Map<String, String> labels, List<File> files) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public String editVoice(String voiceId, String name, Map<String, String> labels, List<File> files) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
EditVoiceRequest editVoiceRequest = new EditVoiceRequest(voiceId,name,files,labels);
|
||||
return (String)(getResult(editVoiceRequest));
|
||||
}
|
||||
@@ -181,15 +181,15 @@ public class ElevenLabsAPI {
|
||||
}
|
||||
}
|
||||
|
||||
private Object getResult(ElevenLabsRequest<?> request) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
private Object getResult(ElevenLabsRequest<?> request) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
ElevenLabsResponse<?> response = sendRequest(request);
|
||||
checkOrThrow(response);
|
||||
return response.getResult();
|
||||
}
|
||||
|
||||
private ElevenLabsResponse<?> sendRequest(ElevenLabsRequest<?> request) throws IOException, ElevenAPINotInitiatedException {
|
||||
private ElevenLabsResponse<?> sendRequest(ElevenLabsRequest<?> request) throws IOException, ElevenLabsAPINotInitiatedException {
|
||||
if(!instantiated){
|
||||
throw new ElevenAPINotInitiatedException();
|
||||
throw new ElevenLabsAPINotInitiatedException();
|
||||
}
|
||||
String formattedEndpoint = request.getFormattedEndpoint();
|
||||
String boundary = "---------------------------" + System.currentTimeMillis();
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs.elements;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.elements.voice.Voice;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
|
||||
import java.io.File;
|
||||
@@ -65,12 +65,12 @@ public class VoiceBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Voice edit() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public Voice edit() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
ElevenLabsAPI.getInstance().editVoice(voiceId, name, labels, files);
|
||||
return ElevenLabsAPI.getInstance().getVoice(voiceId, true);
|
||||
}
|
||||
|
||||
public Voice create() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public Voice create() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
if(files.isEmpty()){
|
||||
throw new ElevenLabsValidationException("Cannot build a voice without any files.");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs.elements.user;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.enums.Status;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -26,7 +26,7 @@ public class Subscription {
|
||||
private final Status status;
|
||||
private final NextInvoice nextInvoice;
|
||||
|
||||
public static Subscription get() throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public static Subscription get() throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getSubscription();
|
||||
}
|
||||
|
||||
@@ -164,8 +164,6 @@ public class Subscription {
|
||||
}
|
||||
|
||||
public record SupportedLanguage(String isoCode, String displayName) {
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SupportedLanguage{" +
|
||||
@@ -176,8 +174,6 @@ public class Subscription {
|
||||
}
|
||||
|
||||
public record NextInvoice(int amountDueCents, long nextPaymentAttemptUnix) {
|
||||
|
||||
|
||||
public Date getNextPaymentAttempt() {
|
||||
return new Date(nextPaymentAttemptUnix);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs.elements.user;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.elements.voice.History;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class User {
|
||||
private final boolean isNewUser;
|
||||
private final String apiKey;
|
||||
|
||||
public static User get() throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public static User get() throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getUser();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class User {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public History getHistory() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public History getHistory() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getHistory();
|
||||
}
|
||||
public static User fromJSON(JSONObject object) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs.elements.voice;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.enums.State;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -38,7 +38,7 @@ public record History(List<HistoryItem> history) {
|
||||
return history;
|
||||
}
|
||||
|
||||
public static History get() throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public static History get() throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getHistory();
|
||||
}
|
||||
|
||||
@@ -52,11 +52,11 @@ public record History(List<HistoryItem> history) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public File downloadHistory(String[] ids, File file) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File downloadHistory(String[] ids, File file) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().downloadHistory(Arrays.stream(ids).toList(), file);
|
||||
}
|
||||
|
||||
public File downloadHistory(List<HistoryItem> historyItems, File file) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File downloadHistory(List<HistoryItem> historyItems, File file) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().downloadHistory(historyItems.stream().map(HistoryItem::getHistoryItemId).collect(Collectors.toList()), file);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public record History(List<HistoryItem> history) {
|
||||
private final String contentType;
|
||||
private final State state;
|
||||
private Voice voice;
|
||||
private History history;
|
||||
private final History history;
|
||||
|
||||
public HistoryItem(String historyItemId, String voiceId, String voiceName, String text, long dateUnix, int characterCountChangeFrom, int characterCountChangeTo, String contentType, String state, History history) {
|
||||
this.historyItemId = historyItemId;
|
||||
@@ -98,9 +98,7 @@ public record History(List<HistoryItem> history) {
|
||||
if (voice == null) {
|
||||
try {
|
||||
voice = ElevenLabsAPI.getInstance().getVoice(voiceId);
|
||||
} catch (ElevenLabsValidationException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (ElevenAPINotInitiatedException e) {
|
||||
} catch (ElevenLabsValidationException | IOException | ElevenLabsAPINotInitiatedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -147,13 +145,13 @@ public record History(List<HistoryItem> history) {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String delete() throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public String delete() throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
String output = ElevenLabsAPI.getInstance().deleteHistoryItem(this);
|
||||
history.history.remove(this);
|
||||
return output;
|
||||
}
|
||||
|
||||
public File downloadAudio(File outputFile) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public File downloadAudio(File outputFile) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getHistoryItemAudio(this, outputFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.elements.voice;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -64,11 +64,11 @@ public class Sample {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String delete() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String delete() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().deleteSample(voice,this);
|
||||
}
|
||||
|
||||
public File downloadAudio(File outputFile) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public File downloadAudio(File outputFile) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getSampleAudio(voice, this, outputFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs.elements.voice;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.elements.VoiceBuilder;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -29,11 +29,13 @@ public class Voice {
|
||||
public static Voice fromJSON(JSONObject object) {
|
||||
String voiceId = (String) object.get("voice_id");
|
||||
String name = (String) object.get("name");
|
||||
JSONArray samplesJson = (JSONArray) object.get("samples");
|
||||
List<Sample> samples = new ArrayList<>();
|
||||
for (Object sampleObj : samplesJson) {
|
||||
JSONObject sampleJson = (JSONObject) sampleObj;
|
||||
samples.add(Sample.fromJSON(sampleJson));
|
||||
if(object.containsKey("samples") && object.get("samples") != null){
|
||||
JSONArray samplesJson = (JSONArray) object.get("samples");
|
||||
for (Object sampleObj : samplesJson) {
|
||||
JSONObject sampleJson = (JSONObject) sampleObj;
|
||||
samples.add(Sample.fromJSON(sampleJson));
|
||||
}
|
||||
}
|
||||
String category = (String) object.get("category");
|
||||
JSONObject labelsJson = (JSONObject) object.get("labels");
|
||||
@@ -53,8 +55,8 @@ public class Voice {
|
||||
double sim = -1;
|
||||
if(object.containsKey("settings") && object.get("settings") != null){
|
||||
JSONObject settingsJson = (JSONObject) object.get("settings");
|
||||
VoiceSettings settings = new VoiceSettings(((Long) settingsJson.get("stability")).doubleValue(),
|
||||
((Long) settingsJson.get("similarity_boost")).doubleValue());
|
||||
VoiceSettings settings = new VoiceSettings(((Double) settingsJson.get("stability")),
|
||||
((Double) settingsJson.get("similarity_boost")));
|
||||
stab = settings.getStability();
|
||||
sim = settings.getSimilarityBoost();
|
||||
}
|
||||
@@ -67,17 +69,17 @@ public class Voice {
|
||||
|
||||
|
||||
|
||||
public static List<Voice> getVoices() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public static List<Voice> getVoices() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getVoices();
|
||||
}
|
||||
|
||||
public static Voice get(String voiceId) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public static Voice get(String voiceId) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
Voice voice = ElevenLabsAPI.getInstance().getVoice(voiceId);
|
||||
voice.hasSettings = true;
|
||||
return voice;
|
||||
}
|
||||
|
||||
public static Voice get(String voiceId, boolean withSettings) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public static Voice get(String voiceId, boolean withSettings) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
Voice voice = ElevenLabsAPI.getInstance().getVoice(voiceId, withSettings);
|
||||
voice.hasSettings = withSettings;
|
||||
return voice;
|
||||
@@ -127,11 +129,11 @@ public class Voice {
|
||||
return voiceSettings;
|
||||
}
|
||||
|
||||
public String delete() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String delete() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().deleteVoice(getVoiceId());
|
||||
}
|
||||
|
||||
public void fetchSettings() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public void fetchSettings() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
this.voiceSettings = ElevenLabsAPI.getInstance().getVoiceSettings(getVoiceId());
|
||||
hasSettings = true;
|
||||
}
|
||||
@@ -140,7 +142,7 @@ public class Voice {
|
||||
return VoiceBuilder.fromVoice(this);
|
||||
}
|
||||
|
||||
public String updateVoiceSettings(VoiceSettings settings) throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public String updateVoiceSettings(VoiceSettings settings) throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
String response = ElevenLabsAPI.getInstance().editVoice(this, settings);
|
||||
if(response != null){
|
||||
this.voiceSettings = settings;
|
||||
@@ -150,11 +152,11 @@ public class Voice {
|
||||
return null;
|
||||
}
|
||||
|
||||
public File generate(String text, VoiceSettings voiceSettings, File output) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public File generate(String text, VoiceSettings voiceSettings, File output) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getTextToSpeech(text, this, voiceSettings,output);
|
||||
}
|
||||
|
||||
public File generate(String text, File output) throws ElevenLabsValidationException, IOException, ElevenAPINotInitiatedException {
|
||||
public File generate(String text, File output) throws ElevenLabsValidationException, IOException, ElevenLabsAPINotInitiatedException {
|
||||
if(!hasSettings){
|
||||
throw new ElevenLabsValidationException("Cannot use default voice settings for " + voiceId + " because this object does not have VoiceSettings");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.elements.voice;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsAPINotInitiatedException;
|
||||
import net.andrewcpu.elevenlabs.exceptions.ElevenLabsValidationException;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -15,7 +15,7 @@ public class VoiceSettings {
|
||||
public static VoiceSettings fromJSON(JSONObject object){
|
||||
return new VoiceSettings((double)object.get("stability"), (double)object.get("similarity"));
|
||||
}
|
||||
public static VoiceSettings getDefaultVoiceSettings() throws IOException, ElevenLabsValidationException, ElevenAPINotInitiatedException {
|
||||
public static VoiceSettings getDefaultVoiceSettings() throws IOException, ElevenLabsValidationException, ElevenLabsAPINotInitiatedException {
|
||||
return ElevenLabsAPI.getInstance().getDefaultVoiceSettings();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package net.andrewcpu.elevenlabs.exceptions;
|
||||
|
||||
public class ElevenAPINotInitiatedException extends Exception{
|
||||
public ElevenAPINotInitiatedException() {
|
||||
super("ElevenLabs API has not been initiated.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.exceptions;
|
||||
|
||||
public class ElevenLabsAPINotInitiatedException extends Exception{
|
||||
public ElevenLabsAPINotInitiatedException() {
|
||||
super("ElevenLabs API has not been initiated.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user