mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-05-06 03:00:23 -04:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
388d059af7 | ||
|
|
1f9c48eac6 | ||
|
|
b3ea0e2a09 | ||
|
|
75eb64a077 | ||
|
|
c5706317aa | ||
|
|
0a2f6d1869 | ||
|
|
b753769a53 | ||
|
|
8162cada71 | ||
|
|
fdcc12ee41 | ||
|
|
8c526a1539 | ||
|
|
95cf38c620 | ||
|
|
6968219c55 | ||
|
|
e6279b689f |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Dev Build
|
name: Build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|||||||
116
README.md
116
README.md
@@ -4,15 +4,19 @@
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
So you wanna make custom voices, huh? Well you've come to the right place.
|
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.
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
**Maven**
|
**Maven**
|
||||||
|
|
||||||
To add `elevenlabs-api` to your Maven project, use:
|
To add `elevenlabs-api` to your Maven project, use:
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.andrewcpu.elevenlabs</groupId>
|
<groupId>net.andrewcpu</groupId>
|
||||||
<artifactId>elevenlabs-api</artifactId>
|
<artifactId>elevenlabs-api</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
The most up-to date package information can be found on the [Packages tab](https://github.com/AndrewCPU/elevenlabs-api/packages/)
|
The most up-to date package information can be found on the [Packages tab](https://github.com/AndrewCPU/elevenlabs-api/packages/)
|
||||||
@@ -27,11 +31,10 @@ Compiled JARs are available via the [Releases tab](https://github.com/AndrewCPU/
|
|||||||
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 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:
|
To set up your ElevenLabs API key, you must register it with the ElevenLabsAPI Java API like below:
|
||||||
```java
|
```java
|
||||||
ElevenLabsAPI.getInstance().setAPIKey("YOUR_API_KEY_HERE");
|
ElevenLabs.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.*
|
*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 `ElevenLabsAPINotInitiatedException`.
|
|
||||||
- - -
|
- - -
|
||||||
|
|
||||||
<!-- TOC -->
|
<!-- TOC -->
|
||||||
@@ -66,9 +69,6 @@ Once you've injected your API Key, you can safely assume that you will not recei
|
|||||||
* [Exceptions](#exceptions)
|
* [Exceptions](#exceptions)
|
||||||
* [*ElevenLabsAPINotInitiatedException*](#elevenlabsapinotinitiatedexception)
|
* [*ElevenLabsAPINotInitiatedException*](#elevenlabsapinotinitiatedexception)
|
||||||
* [*ElevenLabsValidationException*](#elevenlabsvalidationexception)
|
* [*ElevenLabsValidationException*](#elevenlabsvalidationexception)
|
||||||
* [Built in Types](#built-in-types)
|
|
||||||
* [`Voice` Related Types](#voice-related-types)
|
|
||||||
* [`User` Related Types](#user-related-types)
|
|
||||||
* [Misc](#misc)
|
* [Misc](#misc)
|
||||||
|
|
||||||
* [Links to ElevenLabs](#links-to-elevenlabs)
|
* [Links to ElevenLabs](#links-to-elevenlabs)
|
||||||
@@ -168,8 +168,15 @@ To generate an audio file with a given `Voice`, you can utilize the `Voice#gener
|
|||||||
Depending on how you access your `Voice`, (with or without settings), will decide whether you can use the implicit `voiceSettings` or if you have to specify the `VoiceSettings` object to use. Unless explicitly requesting the `Voice` without settings, every `Voice` object SHOULD contain its default `VoiceSettings`.
|
Depending on how you access your `Voice`, (with or without settings), will decide whether you can use the implicit `voiceSettings` or if you have to specify the `VoiceSettings` object to use. Unless explicitly requesting the `Voice` without settings, every `Voice` object SHOULD contain its default `VoiceSettings`.
|
||||||
```java
|
```java
|
||||||
Voice voice;
|
Voice voice;
|
||||||
File outputFile = voice.generate(String text, VoiceSettings voiceSettings, File output);
|
File file = voice.generate(String text);
|
||||||
File outputFile = voice.generate(String text, File output); // Uses default voice settings
|
File file = voice.generate(String text, VoiceSettings settings);
|
||||||
|
File file = voice.generate(String text, String model, VoiceSettings settings);
|
||||||
|
File file = voice.generate(String text, String model);
|
||||||
|
|
||||||
|
InputStream inputStream = voice.generateStream(String text);
|
||||||
|
InputStream inputStream = voice.generateStream(String text, VoiceSettings settings);
|
||||||
|
InputStream inputStream = voice.generateStream(String text, String model, VoiceSettings settings);
|
||||||
|
InputStream inputStream = voice.generateStream(String text, String model);
|
||||||
```
|
```
|
||||||
- - -
|
- - -
|
||||||
|
|
||||||
@@ -186,7 +193,7 @@ You can download a `Sample` via the `Sample#downloadAudio(File outputFile)` func
|
|||||||
The `File` parameter of `downloadAudio()` is the location of where you want to locally download the sample.
|
The `File` parameter of `downloadAudio()` is the location of where you want to locally download the sample.
|
||||||
```java
|
```java
|
||||||
Voice voice;
|
Voice voice;
|
||||||
File file = voice.getSamples().get(0).downloadAudio(File outputFile);
|
File file = voice.getSamples().get(0).downloadAudio();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Deleting a Sample
|
### Deleting a Sample
|
||||||
@@ -214,11 +221,11 @@ HistoryItem item = history.getHistoryItem("itemId");
|
|||||||
|
|
||||||
### Downloading History
|
### 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<HistoryItem>` parameter.
|
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<HistoryItem>` parameter.
|
||||||
The second parameter is the path in which you would like to save the ZIP file.
|
|
||||||
```java
|
```java
|
||||||
History history;
|
History history;
|
||||||
File download = history.downloadHistory(new String[]{"item-id1", "item-id2"}, new File("outputFile.zip"));
|
File download = history.downloadHistory(new String[]{"item-id1", "item-id2"});
|
||||||
File download = history.downloadHistory(List<HistoryItem> historyItems, File outputFile);
|
File download = history.downloadHistory(List<HistoryItem> historyItems);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Deleting a HistoryItem
|
### Deleting a HistoryItem
|
||||||
@@ -236,10 +243,10 @@ Voice voice = item.getVoice();
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Downloading a HistoryItem Audio
|
### 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.
|
A `HistoryItem` is a previous TTS generation. You can download the generation as an MP3 file by executing the `downloadAudio()` function. The return value is the tmp `File` location of your download.
|
||||||
```java
|
```java
|
||||||
HistoryItem item;
|
HistoryItem item;
|
||||||
File file = item.downloadAudio(File outputFile);
|
File file = item.downloadAudio();
|
||||||
```
|
```
|
||||||
- - -
|
- - -
|
||||||
|
|
||||||
@@ -259,77 +266,8 @@ User user = User.get();
|
|||||||
|
|
||||||
- - -
|
- - -
|
||||||
## Exceptions
|
## Exceptions
|
||||||
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*
|
### *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.
|
This error indicates a malformed request to the ElevenLabs API. The exception should provide the location of any syntactically incorrect parameters within the request.
|
||||||
- - -
|
|
||||||
# Built in Types
|
|
||||||
|
|
||||||
There are a few objects and enums defined for this API.
|
|
||||||
## `Voice` Related Types
|
|
||||||
```java
|
|
||||||
Voice(String voiceId, String name, List<Sample> samples, String category,
|
|
||||||
Map<String, String> labels, String previewUrl, List<String> availableForTiers,
|
|
||||||
VoiceSettings settings)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
VoiceSettings(double stability, double similarityBoost)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
Sample(String sampleId, String fileName, String mimeType, long sizeBytes, String hash)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
History(List<HistoryItem> history)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
History.HistoryItem(String historyItemId, String voiceId, String voiceName, String text,
|
|
||||||
long dateUnix, int characterCountChangeFrom, int characterCountChangeTo,
|
|
||||||
String contentType, GenerationState state)
|
|
||||||
```
|
|
||||||
|
|
||||||
```java
|
|
||||||
public enum GenerationState {
|
|
||||||
CREATED,
|
|
||||||
DELETED,
|
|
||||||
PROCESSING;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
- - -
|
|
||||||
## `User` Related Types
|
|
||||||
```java
|
|
||||||
User(Subscription subscription, boolean isNewUser, String xiApiKey)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
Subscription(String tier, int characterCount, int characterLimit, boolean canExtendCharacterLimit,
|
|
||||||
boolean allowedToExtendCharacterLimit, long nextCharacterCountResetUnix, int voiceLimit,
|
|
||||||
boolean canExtendVoiceLimit, boolean canUseInstantVoiceCloning, List<AvailableModel> availableModels,
|
|
||||||
AccountStatus status, NextInvoice nextInvoice)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
AvailableModel(String modelId, String displayName, List<SupportedLanguage> supportedLanguages)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
SupportedLanguage(String isoCode, String displayName)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
NextInvoice(int amountDueCents, long nextPaymentAttemptUnix)
|
|
||||||
```
|
|
||||||
```java
|
|
||||||
public enum AccountStatus {
|
|
||||||
TRIALING,
|
|
||||||
ACTIVE,
|
|
||||||
INCOMPLETE,
|
|
||||||
INCOMPLETE_EXPIRED,
|
|
||||||
PAST_DUE,
|
|
||||||
CANCELED,
|
|
||||||
UNPAID,
|
|
||||||
FREE;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
- - -
|
- - -
|
||||||
|
|
||||||
@@ -341,7 +279,15 @@ If you like what you see, give it a star! :)
|
|||||||
- - -
|
- - -
|
||||||
|
|
||||||
#### Unit Testing
|
#### Unit Testing
|
||||||
*Todo*
|
Unit tests have been created, these endpoints are destructive and not included in the testing:
|
||||||
|
* deleteHistoryItem - WONT TEST
|
||||||
|
* deleteSample - WONT TEST
|
||||||
|
* deleteVoice - WONT TEST
|
||||||
|
* editVoiceSettings - WONT TEST
|
||||||
|
* createVoice - WONT TEST
|
||||||
|
* editVoice - WONT TEST
|
||||||
|
|
||||||
|
To run the unit tests yourself, you have to clone this repo and update the ElevenLabsTest.java file with your API key and your voice to test on.
|
||||||
|
|
||||||
|
|
||||||
Thanks to ElevenLabs for making an awesome tool 🥂
|
Thanks to ElevenLabs for making an awesome tool 🥂
|
||||||
|
|||||||
95
pom.xml
95
pom.xml
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
<name>Unofficial Java ElevenLabs Voice API</name>
|
<name>Unofficial Java ElevenLabs Voice API</name>
|
||||||
<description>An API level interaction between Java and the ElevenLabs Voice Generation Web API.</description>
|
<description>An API level interaction between Java and the ElevenLabs Voice Generation Web API.</description>
|
||||||
|
<url>https://github.com/AndrewCPU/elevenlabs-api</url>
|
||||||
<developers>
|
<developers>
|
||||||
<developer>
|
<developer>
|
||||||
<id>Andrewcpu</id>
|
<id>Andrewcpu</id>
|
||||||
@@ -24,17 +25,42 @@
|
|||||||
<tag>HEAD</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<profiles>
|
||||||
<repository>
|
<profile>
|
||||||
<id>github</id>
|
<id>github</id>
|
||||||
<name>GitHub AndrewCPU Apache Maven Packages</name>
|
<activation>
|
||||||
<url>https://maven.pkg.github.com/AndrewCPU/elevenlabs-api</url>
|
<activeByDefault>false</activeByDefault>
|
||||||
</repository>
|
</activation>
|
||||||
</distributionManagement>
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>github</id>
|
||||||
|
<name>GitHub AndrewCPU Apache Maven Packages</name>
|
||||||
|
<url>https://maven.pkg.github.com/AndrewCPU/elevenlabs-api</url>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
</profile>
|
||||||
|
<profile>
|
||||||
|
<id>ossrh</id>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>ossrh</id>
|
||||||
|
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||||
|
</repository>
|
||||||
|
<snapshotRepository>
|
||||||
|
<id>ossrh</id>
|
||||||
|
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
</snapshotRepository>
|
||||||
|
</distributionManagement>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
|
||||||
<groupId>net.andrewcpu</groupId>
|
<groupId>net.andrewcpu</groupId>
|
||||||
<artifactId>elevenlabs-api</artifactId>
|
<artifactId>elevenlabs-api</artifactId>
|
||||||
<version>2.0-SNAPSHOT</version>
|
<version>2.2</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>11</maven.compiler.source>
|
<maven.compiler.source>11</maven.compiler.source>
|
||||||
@@ -94,6 +120,20 @@
|
|||||||
<build>
|
<build>
|
||||||
<finalName>elevenlabs-api-${version}</finalName>
|
<finalName>elevenlabs-api-${version}</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>sign-artifacts</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>sign</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.3.0</version>
|
||||||
@@ -114,6 +154,47 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<!-- Generates JAR's source file -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.sonatype.plugins</groupId>
|
||||||
|
<artifactId>nexus-staging-maven-plugin</artifactId>
|
||||||
|
<version>1.6.13</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<serverId>ossrh</serverId>
|
||||||
|
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
|
||||||
|
<autoReleaseAfterClose>true</autoReleaseAfterClose>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<!-- Generates Javadoc JAR file -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadocs</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs;
|
package net.andrewcpu.elevenlabs;
|
||||||
|
|
||||||
|
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.History;
|
||||||
import net.andrewcpu.elevenlabs.model.history.HistoryItem;
|
import net.andrewcpu.elevenlabs.model.history.HistoryItem;
|
||||||
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
|
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
|
||||||
@@ -9,16 +11,16 @@ import net.andrewcpu.elevenlabs.model.user.Subscription;
|
|||||||
import net.andrewcpu.elevenlabs.model.user.User;
|
import net.andrewcpu.elevenlabs.model.user.User;
|
||||||
import net.andrewcpu.elevenlabs.model.voice.Voice;
|
import net.andrewcpu.elevenlabs.model.voice.Voice;
|
||||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||||
import net.andrewcpu.elevenlabs.net.ElevenRequest;
|
import net.andrewcpu.elevenlabs.requests.ElevenLabsRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.history.*;
|
import net.andrewcpu.elevenlabs.requests.history.*;
|
||||||
import net.andrewcpu.elevenlabs.net.models.GetModelsRequest;
|
import net.andrewcpu.elevenlabs.requests.models.GetModelsRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.samples.DeleteSampleRequest;
|
import net.andrewcpu.elevenlabs.requests.samples.DeleteSampleRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.samples.GetSampleRequest;
|
import net.andrewcpu.elevenlabs.requests.samples.GetSampleRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.tts.PostTextToSpeechRequest;
|
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.tts.PostTextToSpeechStreamedRequest;
|
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechStreamedRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.user.GetSubscriptionRequest;
|
import net.andrewcpu.elevenlabs.requests.user.GetSubscriptionRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.user.GetUserRequest;
|
import net.andrewcpu.elevenlabs.requests.user.GetUserRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.voices.*;
|
import net.andrewcpu.elevenlabs.requests.voices.*;
|
||||||
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -37,7 +39,7 @@ public class ElevenLabs {
|
|||||||
API_KEY = apiKey;
|
API_KEY = apiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> T sendRequest(ElevenRequest<T> request) {
|
private static <T> T sendRequest(ElevenLabsRequest<T> request) {
|
||||||
return ElevenNetworkUtil.sendRequest(request.getType(),request.getEndpoint(), request.getPayload(),request.getResponseClass());
|
return ElevenNetworkUtil.sendRequest(request.getType(),request.getEndpoint(), request.getPayload(),request.getResponseClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +122,13 @@ public class ElevenLabs {
|
|||||||
return sendRequest(new PostTextToSpeechRequest(voiceId, new TextToSpeechRequest(text, modelId, voiceSettings)));
|
return sendRequest(new PostTextToSpeechRequest(voiceId, new TextToSpeechRequest(text, modelId, voiceSettings)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File generateTextToSpeech(String voiceId, String text, String modelId, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization, VoiceSettings voiceSettings) {
|
||||||
|
return sendRequest(new PostTextToSpeechRequest(voiceId, new TextToSpeechRequest(text, modelId, voiceSettings), streamLatencyOptimization, outputFormat));
|
||||||
|
}
|
||||||
|
public static InputStream generateTextToSpeechStreamed(String voiceId, String text, String modelId, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization, VoiceSettings voiceSettings) {
|
||||||
|
return sendRequest(new PostTextToSpeechStreamedRequest(voiceId, new TextToSpeechRequest(text, modelId, voiceSettings), streamLatencyOptimization, outputFormat));
|
||||||
|
}
|
||||||
|
|
||||||
public static InputStream generateTextToSpeechStreamed(String voiceId, String text, String modelId, VoiceSettings voiceSettings) {
|
public static InputStream generateTextToSpeechStreamed(String voiceId, String text, String modelId, VoiceSettings voiceSettings) {
|
||||||
return sendRequest(new PostTextToSpeechStreamedRequest(voiceId, new TextToSpeechRequest(text, modelId, voiceSettings)));
|
return sendRequest(new PostTextToSpeechStreamedRequest(voiceId, new TextToSpeechRequest(text, modelId, voiceSettings)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.enums;
|
||||||
|
|
||||||
|
public enum GeneratedAudioOutputFormat {
|
||||||
|
MP3_44100_64,
|
||||||
|
MP3_44100_96,
|
||||||
|
MP3_44100_128,
|
||||||
|
MP3_44100_192,
|
||||||
|
PCM_16000,
|
||||||
|
PCM_22050,
|
||||||
|
PCM_24000,
|
||||||
|
PCM_44100,
|
||||||
|
ULAW_8000;
|
||||||
|
|
||||||
|
|
||||||
|
// Method to get the default value
|
||||||
|
public static GeneratedAudioOutputFormat getDefault() {
|
||||||
|
return MP3_44100_128;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.andrewcpu.elevenlabs;
|
package net.andrewcpu.elevenlabs.enums;
|
||||||
|
|
||||||
public enum HttpRequestType {
|
public enum HttpRequestType {
|
||||||
POST, GET, PUT, DELETE;
|
POST, GET, PUT, DELETE;
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.enums;
|
||||||
|
|
||||||
|
public enum StreamLatencyOptimization {
|
||||||
|
//0 - default mode (no latency optimizations)
|
||||||
|
NONE(0),
|
||||||
|
//1 - normal latency optimizations (about 50% of possible latency improvement of option 3)
|
||||||
|
NORMAL(1),
|
||||||
|
//2 - strong latency optimizations (about 75% of possible latency improvement of option 3)
|
||||||
|
STRONG(2),
|
||||||
|
// 3 - max latency optimizations
|
||||||
|
MAX_TEXT_NORMALIZATION(3),
|
||||||
|
// 3 - max latency optimizations with text normalizer turned off
|
||||||
|
MAX_NO_TEXT_NORMALIZATION(4);
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
StreamLatencyOptimization(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StreamLatencyOptimization getDefault() {
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class History extends ElevenModel {
|
public class History extends ElevenModel {
|
||||||
@@ -31,8 +33,8 @@ public class History extends ElevenModel {
|
|||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public HistoryItem getHistoryItem(String id) {
|
public HistoryItem getHistoryItem(String id) {
|
||||||
for(HistoryItem item : historyItems) {
|
for (HistoryItem item : historyItems) {
|
||||||
if(item.getHistoryItemId().equals(id)){
|
if (item.getHistoryItemId().equals(id)) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +56,14 @@ public class History extends ElevenModel {
|
|||||||
return hasMore;
|
return hasMore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File downloadHistory(String... historyIds) {
|
||||||
|
return ElevenLabs.getHistoryItemAudio(historyIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File downloadHistory(HistoryItem... items) {
|
||||||
|
return ElevenLabs.getHistoryItemAudio(Arrays.stream(items).map(HistoryItem::getHistoryItemId).toArray(String[]::new));
|
||||||
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|||||||
@@ -24,23 +24,46 @@ public class GenerationTypeModel extends ElevenModel {
|
|||||||
@JsonProperty("can_do_voice_conversion")
|
@JsonProperty("can_do_voice_conversion")
|
||||||
private boolean canDoVoiceConversion;
|
private boolean canDoVoiceConversion;
|
||||||
|
|
||||||
|
@JsonProperty("can_use_style")
|
||||||
|
private boolean canUseStyle;
|
||||||
|
|
||||||
|
@JsonProperty("can_use_speaker_boost")
|
||||||
|
private boolean canUseSpeakerBoost;
|
||||||
|
|
||||||
|
@JsonProperty("serves_pro_voices")
|
||||||
|
private boolean servesProVoices;
|
||||||
|
|
||||||
@JsonProperty("token_cost_factor")
|
@JsonProperty("token_cost_factor")
|
||||||
private int tokenCostFactor;
|
private int tokenCostFactor;
|
||||||
|
|
||||||
@JsonProperty("description")
|
@JsonProperty("description")
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@JsonProperty("requires_alpha_access")
|
||||||
|
private boolean requiresAlphaAccess;
|
||||||
|
|
||||||
|
@JsonProperty("max_characters_request_free_user")
|
||||||
|
private int maxCharactersRequestFreeUser;
|
||||||
|
@JsonProperty("max_characters_request_subscribed_user")
|
||||||
|
private int maxCharactersRequestSubscribedUser;
|
||||||
|
|
||||||
@JsonProperty("languages")
|
@JsonProperty("languages")
|
||||||
private List<Language> languages;
|
private List<Language> languages;
|
||||||
|
|
||||||
public GenerationTypeModel(String modelId, String name, boolean canBeFinetuned, boolean canDoTextToSpeech, boolean canDoVoiceConversion, int tokenCostFactor, String description, List<Language> languages) {
|
public GenerationTypeModel(String modelId, String name, boolean canBeFinetuned, boolean canDoTextToSpeech, boolean canDoVoiceConversion, boolean canUseStyle, boolean canUseSpeakerBoost, boolean servesProVoices, int tokenCostFactor, String description, boolean requiresAlphaAccess, int maxCharactersRequestFreeUser, int maxCharactersRequestSubscribedUser, List<Language> languages) {
|
||||||
this.modelId = modelId;
|
this.modelId = modelId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.canBeFinetuned = canBeFinetuned;
|
this.canBeFinetuned = canBeFinetuned;
|
||||||
this.canDoTextToSpeech = canDoTextToSpeech;
|
this.canDoTextToSpeech = canDoTextToSpeech;
|
||||||
this.canDoVoiceConversion = canDoVoiceConversion;
|
this.canDoVoiceConversion = canDoVoiceConversion;
|
||||||
|
this.canUseStyle = canUseStyle;
|
||||||
|
this.canUseSpeakerBoost = canUseSpeakerBoost;
|
||||||
|
this.servesProVoices = servesProVoices;
|
||||||
this.tokenCostFactor = tokenCostFactor;
|
this.tokenCostFactor = tokenCostFactor;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
this.requiresAlphaAccess = requiresAlphaAccess;
|
||||||
|
this.maxCharactersRequestFreeUser = maxCharactersRequestFreeUser;
|
||||||
|
this.maxCharactersRequestSubscribedUser = maxCharactersRequestSubscribedUser;
|
||||||
this.languages = languages;
|
this.languages = languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,17 +110,54 @@ public class GenerationTypeModel extends ElevenModel {
|
|||||||
return languages;
|
return languages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
public boolean isCanUseStyle() {
|
||||||
|
return canUseStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isCanUseSpeakerBoost() {
|
||||||
|
return canUseSpeakerBoost;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isServesProVoices() {
|
||||||
|
return servesProVoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isRequiresAlphaAccess() {
|
||||||
|
return requiresAlphaAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public int getMaxCharactersRequestFreeUser() {
|
||||||
|
return maxCharactersRequestFreeUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public int getMaxCharactersRequestSubscribedUser() {
|
||||||
|
return maxCharactersRequestSubscribedUser;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ModelResponse{" +
|
return "GenerationTypeModel{" +
|
||||||
"modelId='" + modelId + '\'' +
|
"modelId='" + modelId + '\'' +
|
||||||
", name='" + name + '\'' +
|
", name='" + name + '\'' +
|
||||||
", canBeFinetuned=" + canBeFinetuned +
|
", canBeFinetuned=" + canBeFinetuned +
|
||||||
", canDoTextToSpeech=" + canDoTextToSpeech +
|
", canDoTextToSpeech=" + canDoTextToSpeech +
|
||||||
", canDoVoiceConversion=" + canDoVoiceConversion +
|
", canDoVoiceConversion=" + canDoVoiceConversion +
|
||||||
|
", canUseStyle=" + canUseStyle +
|
||||||
|
", canUseSpeakerBoost=" + canUseSpeakerBoost +
|
||||||
|
", servesProVoices=" + servesProVoices +
|
||||||
", tokenCostFactor=" + tokenCostFactor +
|
", tokenCostFactor=" + tokenCostFactor +
|
||||||
", description='" + description + '\'' +
|
", description='" + description + '\'' +
|
||||||
|
", requiresAlphaAccess=" + requiresAlphaAccess +
|
||||||
|
", maxCharactersRequestFreeUser=" + maxCharactersRequestFreeUser +
|
||||||
|
", maxCharactersRequestSubscribedUser=" + maxCharactersRequestSubscribedUser +
|
||||||
", languages=" + languages +
|
", languages=" + languages +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,13 @@ package net.andrewcpu.elevenlabs.model.voice;
|
|||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||||
|
import net.andrewcpu.elevenlabs.enums.GeneratedAudioOutputFormat;
|
||||||
|
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||||
import net.andrewcpu.elevenlabs.model.tuning.FineTuning;
|
import net.andrewcpu.elevenlabs.model.tuning.FineTuning;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -56,6 +60,9 @@ public class Voice extends ElevenModel {
|
|||||||
@JsonProperty("sharing")
|
@JsonProperty("sharing")
|
||||||
private Sharing sharing;
|
private Sharing sharing;
|
||||||
|
|
||||||
|
@JsonProperty("high_quality_base_model_ids")
|
||||||
|
private List<String> highQualityBaseModelIds;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public String getVoiceId() {
|
public String getVoiceId() {
|
||||||
return voiceId;
|
return voiceId;
|
||||||
@@ -141,11 +148,106 @@ public class Voice extends ElevenModel {
|
|||||||
this.sharing = refreshedData.sharing;
|
this.sharing = refreshedData.sharing;
|
||||||
this.previewUrl = refreshedData.previewUrl;
|
this.previewUrl = refreshedData.previewUrl;
|
||||||
this.category = refreshedData.category;
|
this.category = refreshedData.category;
|
||||||
|
this.highQualityBaseModelIds = refreshedData.highQualityBaseModelIds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
public File generate(String text, String model) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, model, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File generate(String text, String model, VoiceSettings settings) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, model, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File generate(String text, String model, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId,text, model, outputFormat,streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
public File generate(String text, String model, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId,text, model, outputFormat,StreamLatencyOptimization.getDefault(), settings);
|
||||||
|
}
|
||||||
|
public File generate(String text, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,StreamLatencyOptimization.getDefault(), settings);
|
||||||
|
}
|
||||||
|
public File generate(String text, VoiceSettings settings, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(),streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File generate(String text, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
public File generate(String text, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
public File generate(String text, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File generate(String text, VoiceSettings settings) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File generate(String text) {
|
||||||
|
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, String model) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, String model, VoiceSettings settings) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, VoiceSettings settings) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, String model, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, String model, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization, VoiceSettings settings) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, VoiceSettings settings, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, String model, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, String model, StreamLatencyOptimization streamLatencyOptimization, VoiceSettings settings) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, VoiceSettings settings, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream generateStream(String text, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Voice{" +
|
return "Voice{" +
|
||||||
"voiceId='" + voiceId + '\'' +
|
"voiceId='" + voiceId + '\'' +
|
||||||
@@ -159,6 +261,7 @@ public class Voice extends ElevenModel {
|
|||||||
", availableForTiers=" + availableForTiers +
|
", availableForTiers=" + availableForTiers +
|
||||||
", settings=" + settings +
|
", settings=" + settings +
|
||||||
", sharing=" + sharing +
|
", sharing=" + sharing +
|
||||||
|
", highQualityBaseModelIds=" + highQualityBaseModelIds +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,24 @@ public class VoiceSettings extends ElevenModel {
|
|||||||
@JsonProperty("similarity_boost")
|
@JsonProperty("similarity_boost")
|
||||||
private double similarityBoost;
|
private double similarityBoost;
|
||||||
|
|
||||||
|
@JsonProperty("style")
|
||||||
|
private double style;
|
||||||
|
|
||||||
|
@JsonProperty("use_speaker_boost")
|
||||||
|
private boolean useSpeakerBoost;
|
||||||
|
|
||||||
|
public VoiceSettings(double stability, double similarityBoost, double style, boolean useSpeakerBoost) {
|
||||||
|
this.stability = stability;
|
||||||
|
this.similarityBoost = similarityBoost;
|
||||||
|
this.style = style;
|
||||||
|
this.useSpeakerBoost = useSpeakerBoost;
|
||||||
|
}
|
||||||
|
|
||||||
public VoiceSettings(double stability, double similarityBoost) {
|
public VoiceSettings(double stability, double similarityBoost) {
|
||||||
this.stability = stability;
|
this.stability = stability;
|
||||||
this.similarityBoost = similarityBoost;
|
this.similarityBoost = similarityBoost;
|
||||||
|
this.style = 0;
|
||||||
|
this.useSpeakerBoost = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VoiceSettings() {
|
public VoiceSettings() {
|
||||||
@@ -34,11 +49,23 @@ public class VoiceSettings extends ElevenModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
public double getStyle() {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public boolean isUseSpeakerBoost() {
|
||||||
|
return useSpeakerBoost;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@JsonIgnore
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "VoiceSettings{" +
|
return "VoiceSettings{" +
|
||||||
"stability=" + stability +
|
"stability=" + stability +
|
||||||
", similarityBoost=" + similarityBoost +
|
", similarityBoost=" + similarityBoost +
|
||||||
|
", style=" + style +
|
||||||
|
", useSpeakerBoost=" + useSpeakerBoost +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
|
||||||
|
|
||||||
public abstract class DeleteRequest<T> extends ElevenRequest<T> {
|
|
||||||
public DeleteRequest(String endpoint, Class<T> clazz) {
|
|
||||||
super(HttpRequestType.DELETE, endpoint, clazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
|
||||||
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
|
||||||
|
|
||||||
public abstract class ElevenRequest<T> {
|
|
||||||
private HttpRequestType type;
|
|
||||||
private String endpoint;
|
|
||||||
private Class<T> responseClass;
|
|
||||||
|
|
||||||
public ElevenRequest(HttpRequestType type, String endpoint, Class<T> clazz) {
|
|
||||||
this.type = type;
|
|
||||||
this.endpoint = endpoint;
|
|
||||||
this.responseClass = clazz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HttpRequestType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEndpoint() {
|
|
||||||
return endpoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Class<T> getResponseClass() {
|
|
||||||
return responseClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Object getPayload();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
|
||||||
|
|
||||||
public abstract class GetRequest<T> extends ElevenRequest<T> {
|
|
||||||
public GetRequest(String endpoint, Class<T> clazz) {
|
|
||||||
super(HttpRequestType.GET, endpoint, clazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
|
||||||
|
|
||||||
public abstract class PostRequest<T> extends ElevenRequest<T> {
|
|
||||||
public PostRequest(String endpoint, Class<T> clazz) {
|
|
||||||
super(HttpRequestType.POST, endpoint, clazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
|
||||||
|
|
||||||
public abstract class PutRequest<T> extends ElevenRequest<T> {
|
|
||||||
public PutRequest(String endpoint, Class<T> clazz) {
|
|
||||||
super(HttpRequestType.PUT, endpoint, clazz);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.tts;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
|
|
||||||
import net.andrewcpu.elevenlabs.net.PostRequest;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class PostTextToSpeechRequest extends PostRequest<File> {
|
|
||||||
private TextToSpeechRequest request;
|
|
||||||
public PostTextToSpeechRequest(String voiceId, TextToSpeechRequest request) {
|
|
||||||
super("v1/text-to-speech/" + voiceId, File.class);
|
|
||||||
this.request = request;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getPayload() {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.tts;
|
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
|
|
||||||
import net.andrewcpu.elevenlabs.net.PostRequest;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class PostTextToSpeechStreamedRequest extends PostRequest<InputStream> {
|
|
||||||
private TextToSpeechRequest request;
|
|
||||||
public PostTextToSpeechStreamedRequest(String voiceId, TextToSpeechRequest request) {
|
|
||||||
super("v1/text-to-speech/" + voiceId, InputStream.class);
|
|
||||||
this.request = request;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getPayload() {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||||
|
|
||||||
|
public abstract class DeleteRequest<T> extends ElevenLabsRequest<T> {
|
||||||
|
public DeleteRequest(String endpoint, Class<T> clazz) {
|
||||||
|
super(HttpRequestType.DELETE, endpoint, clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public ElevenLabsRequest(HttpRequestType type, String endpoint, Class<T> clazz) {
|
||||||
|
this.type = type;
|
||||||
|
this.endpoint = endpoint;
|
||||||
|
this.responseClass = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpRequestType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEndpoint() {
|
||||||
|
return endpoint + "?" + buildQueryParameters(getQueryParameters());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getQueryParameters() {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Class<T> getResponseClass() {
|
||||||
|
return responseClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Object getPayload();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||||
|
|
||||||
|
public abstract class GetRequest<T> extends ElevenLabsRequest<T> {
|
||||||
|
public GetRequest(String endpoint, Class<T> clazz) {
|
||||||
|
super(HttpRequestType.GET, endpoint, clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||||
|
|
||||||
|
public abstract class PostRequest<T> extends ElevenLabsRequest<T> {
|
||||||
|
public PostRequest(String endpoint, Class<T> clazz) {
|
||||||
|
super(HttpRequestType.POST, endpoint, clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||||
|
|
||||||
|
public abstract class PutRequest<T> extends ElevenLabsRequest<T> {
|
||||||
|
public PutRequest(String endpoint, Class<T> clazz) {
|
||||||
|
super(HttpRequestType.PUT, endpoint, clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.history;
|
package net.andrewcpu.elevenlabs.requests.history;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.net.DeleteRequest;
|
import net.andrewcpu.elevenlabs.requests.DeleteRequest;
|
||||||
|
|
||||||
public class DeleteHistoryItemRequest extends DeleteRequest<String> {
|
public class DeleteHistoryItemRequest extends DeleteRequest<String> {
|
||||||
public DeleteHistoryItemRequest(String historyItemId) {
|
public DeleteHistoryItemRequest(String historyItemId) {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.history;
|
package net.andrewcpu.elevenlabs.requests.history;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.history;
|
package net.andrewcpu.elevenlabs.requests.history;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.history.HistoryItem;
|
import net.andrewcpu.elevenlabs.model.history.HistoryItem;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetHistoryItemByIdRequest extends GetRequest<HistoryItem> {
|
public class GetHistoryItemByIdRequest extends GetRequest<HistoryItem> {
|
||||||
public GetHistoryItemByIdRequest(String historyId) {
|
public GetHistoryItemByIdRequest(String historyId) {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.history;
|
package net.andrewcpu.elevenlabs.requests.history;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.history.History;
|
import net.andrewcpu.elevenlabs.model.history.History;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetHistoryRequest extends GetRequest<History> {
|
public class GetHistoryRequest extends GetRequest<History> {
|
||||||
public GetHistoryRequest() {
|
public GetHistoryRequest() {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.history;
|
package net.andrewcpu.elevenlabs.requests.history;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.history.HistoryItemList;
|
import net.andrewcpu.elevenlabs.model.history.HistoryItemList;
|
||||||
import net.andrewcpu.elevenlabs.net.PostRequest;
|
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.models;
|
package net.andrewcpu.elevenlabs.requests.models;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.response.GenerationTypeModel;
|
import net.andrewcpu.elevenlabs.model.response.GenerationTypeModel;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetModelsRequest extends GetRequest<GenerationTypeModel[]> {
|
public class GetModelsRequest extends GetRequest<GenerationTypeModel[]> {
|
||||||
public GetModelsRequest() {
|
public GetModelsRequest() {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.samples;
|
package net.andrewcpu.elevenlabs.requests.samples;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.net.DeleteRequest;
|
import net.andrewcpu.elevenlabs.requests.DeleteRequest;
|
||||||
|
|
||||||
public class DeleteSampleRequest extends DeleteRequest<String> {
|
public class DeleteSampleRequest extends DeleteRequest<String> {
|
||||||
public DeleteSampleRequest(String voiceId, String sampleId) {
|
public DeleteSampleRequest(String voiceId, String sampleId) {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.samples;
|
package net.andrewcpu.elevenlabs.requests.samples;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests.tts;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.GeneratedAudioOutputFormat;
|
||||||
|
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.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PostTextToSpeechRequest extends PostRequest<File> {
|
||||||
|
private TextToSpeechRequest request;
|
||||||
|
private StreamLatencyOptimization streamLatencyOptimization;
|
||||||
|
private GeneratedAudioOutputFormat outputFormat;
|
||||||
|
|
||||||
|
public PostTextToSpeechRequest(String voiceId, TextToSpeechRequest request) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, File.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = StreamLatencyOptimization.getDefault();
|
||||||
|
this.outputFormat = GeneratedAudioOutputFormat.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostTextToSpeechRequest(String voiceId, TextToSpeechRequest request, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, File.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = streamLatencyOptimization;
|
||||||
|
this.outputFormat = GeneratedAudioOutputFormat.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostTextToSpeechRequest(String voiceId, TextToSpeechRequest request, StreamLatencyOptimization streamLatencyOptimization, GeneratedAudioOutputFormat generatedAudioOutputFormat) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, File.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = streamLatencyOptimization;
|
||||||
|
this.outputFormat = generatedAudioOutputFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostTextToSpeechRequest(String voiceId, TextToSpeechRequest request, GeneratedAudioOutputFormat generatedAudioOutputFormat) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, File.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = StreamLatencyOptimization.getDefault();
|
||||||
|
this.outputFormat = generatedAudioOutputFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getPayload() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package net.andrewcpu.elevenlabs.requests.tts;
|
||||||
|
|
||||||
|
import net.andrewcpu.elevenlabs.enums.GeneratedAudioOutputFormat;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public PostTextToSpeechStreamedRequest(String voiceId, TextToSpeechRequest request) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, InputStream.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = StreamLatencyOptimization.getDefault();
|
||||||
|
this.outputFormat = GeneratedAudioOutputFormat.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostTextToSpeechStreamedRequest(String voiceId, TextToSpeechRequest request, StreamLatencyOptimization streamLatencyOptimization) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, InputStream.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = streamLatencyOptimization;
|
||||||
|
this.outputFormat = GeneratedAudioOutputFormat.getDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostTextToSpeechStreamedRequest(String voiceId, TextToSpeechRequest request, StreamLatencyOptimization streamLatencyOptimization, GeneratedAudioOutputFormat generatedAudioOutputFormat) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, InputStream.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = streamLatencyOptimization;
|
||||||
|
this.outputFormat = generatedAudioOutputFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PostTextToSpeechStreamedRequest(String voiceId, TextToSpeechRequest request, GeneratedAudioOutputFormat generatedAudioOutputFormat) {
|
||||||
|
super("v1/text-to-speech/" + voiceId, InputStream.class);
|
||||||
|
this.request = request;
|
||||||
|
this.streamLatencyOptimization = StreamLatencyOptimization.getDefault();
|
||||||
|
this.outputFormat = generatedAudioOutputFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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());
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getPayload() {
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.user;
|
package net.andrewcpu.elevenlabs.requests.user;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.user.Subscription;
|
import net.andrewcpu.elevenlabs.model.user.Subscription;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetSubscriptionRequest extends GetRequest<Subscription> {
|
public class GetSubscriptionRequest extends GetRequest<Subscription> {
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.user;
|
package net.andrewcpu.elevenlabs.requests.user;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.user.User;
|
import net.andrewcpu.elevenlabs.model.user.User;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetUserRequest extends GetRequest<User> {
|
public class GetUserRequest extends GetRequest<User> {
|
||||||
public GetUserRequest() {
|
public GetUserRequest() {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.net.DeleteRequest;
|
import net.andrewcpu.elevenlabs.requests.DeleteRequest;
|
||||||
|
|
||||||
public class DeleteVoiceRequest extends DeleteRequest<String> {
|
public class DeleteVoiceRequest extends DeleteRequest<String> {
|
||||||
public DeleteVoiceRequest(String voiceId) {
|
public DeleteVoiceRequest(String voiceId) {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetDefaultVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
public class GetDefaultVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
||||||
public GetDefaultVoiceSettingsRequest() {
|
public GetDefaultVoiceSettingsRequest() {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.voice.Voice;
|
import net.andrewcpu.elevenlabs.model.voice.Voice;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
public class GetVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
||||||
public GetVoiceSettingsRequest(String voiceId) {
|
public GetVoiceSettingsRequest(String voiceId) {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.response.VoiceModelResponse;
|
import net.andrewcpu.elevenlabs.model.response.VoiceModelResponse;
|
||||||
import net.andrewcpu.elevenlabs.net.GetRequest;
|
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||||
|
|
||||||
public class GetVoicesRequest extends GetRequest<VoiceModelResponse> {
|
public class GetVoicesRequest extends GetRequest<VoiceModelResponse> {
|
||||||
public GetVoicesRequest() {
|
public GetVoicesRequest() {
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
||||||
import net.andrewcpu.elevenlabs.net.PostRequest;
|
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||||
import net.andrewcpu.elevenlabs.net.PostRequest;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.andrewcpu.elevenlabs.net.voices;
|
package net.andrewcpu.elevenlabs.requests.voices;
|
||||||
|
|
||||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||||
import net.andrewcpu.elevenlabs.net.PostRequest;
|
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||||
|
|
||||||
public class PostEditVoiceSettingsRequest extends PostRequest<String> {
|
public class PostEditVoiceSettingsRequest extends PostRequest<String> {
|
||||||
private VoiceSettings voiceSettings;
|
private VoiceSettings voiceSettings;
|
||||||
@@ -3,12 +3,10 @@ package net.andrewcpu.elevenlabs.util;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||||
import net.andrewcpu.elevenlabs.exceptions.ValidationException;
|
import net.andrewcpu.elevenlabs.exceptions.ValidationException;
|
||||||
import net.andrewcpu.elevenlabs.model.error.ValidationError;
|
import net.andrewcpu.elevenlabs.model.error.ValidationError;
|
||||||
import org.apache.hc.client5.http.classic.HttpClient;
|
|
||||||
import org.apache.hc.client5.http.classic.methods.*;
|
import org.apache.hc.client5.http.classic.methods.*;
|
||||||
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
|
|
||||||
import org.apache.hc.client5.http.entity.mime.FileBody;
|
import org.apache.hc.client5.http.entity.mime.FileBody;
|
||||||
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
|
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.CloseableHttpClient;
|
||||||
@@ -23,11 +21,11 @@ import org.apache.hc.core5.net.URIBuilder;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.net.URLEncoder;
|
||||||
import java.security.interfaces.DSAParams;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
public class ElevenNetworkUtil {
|
public class ElevenNetworkUtil {
|
||||||
private static final String BASE_URL = "https://api.elevenlabs.io/";
|
private static final String BASE_URL = "https://api.elevenlabs.io/";
|
||||||
@@ -38,6 +36,23 @@ public class ElevenNetworkUtil {
|
|||||||
request.setHeader("xi-api-key", ElevenLabs.getApiKey());
|
request.setHeader("xi-api-key", ElevenLabs.getApiKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String buildQueryParameters(Map<String, String> parameters) {
|
||||||
|
StringJoiner queryParameters = new StringJoiner("&");
|
||||||
|
for (Map.Entry<String, String> entry : parameters.entrySet()) {
|
||||||
|
String encodedKey = encodeValue(entry.getKey());
|
||||||
|
String encodedValue = encodeValue(entry.getValue());
|
||||||
|
queryParameters.add(encodedKey + "=" + encodedValue);
|
||||||
|
}
|
||||||
|
return queryParameters.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String encodeValue(String value) {
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(value, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new RuntimeException("Encoding not supported", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static HttpUriRequestBase getRequest(HttpRequestType type, String path) {
|
public static HttpUriRequestBase getRequest(HttpRequestType type, String path) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -141,6 +156,7 @@ public class ElevenNetworkUtil {
|
|||||||
try {
|
try {
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||||
HttpUriRequestBase request = getRequest(method, path, payload);
|
HttpUriRequestBase request = getRequest(method, path, payload);
|
||||||
|
|
||||||
return getRequestResult(responseType, objectMapper, httpclient, request);
|
return getRequestResult(responseType, objectMapper, httpclient, request);
|
||||||
} catch (IOException | ValidationException e) {
|
} catch (IOException | ValidationException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs;
|
|||||||
|
|
||||||
|
|
||||||
public class ElevenLabsTest {
|
public class ElevenLabsTest {
|
||||||
public static final String ELEVEN_LABS_API_KEY = "";
|
public static final String ELEVEN_LABS_API_KEY = System.getenv("ELEVEN_LABS_API_KEY");
|
||||||
public static final String TEST_VOICE = "ZjJOFdM86g4E9U6OhzUo";
|
public static final String TEST_VOICE = "ZjJOFdM86g4E9U6OhzUo";
|
||||||
static {
|
static {
|
||||||
ElevenLabs.setApiKey(ELEVEN_LABS_API_KEY);
|
ElevenLabs.setApiKey(ELEVEN_LABS_API_KEY);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class TextToSpeechTest extends ElevenLabsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDownloadResponse() {
|
public void testDownloadResponse() {
|
||||||
assertFalse("Cannot download tts!", doesThrow(() -> {
|
assertFalse("Cannot download tts!", doesThrow(() -> {
|
||||||
File file = ElevenLabs.generateTextToSpeech(TEST_VOICE, "This is a test", "eleven_monolingual_v1", new VoiceSettings(0.7, 0.7));
|
File file = ElevenLabs.generateTextToSpeech(TEST_VOICE, "This is a test", "eleven_monolingual_v1", new VoiceSettings(0.7, 0.7, 0, true));
|
||||||
file.delete();
|
file.delete();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public class TextToSpeechTest extends ElevenLabsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testStreamedResponse() {
|
public void testStreamedResponse() {
|
||||||
assertFalse("Cannot strem tts!", doesThrow(() -> {
|
assertFalse("Cannot strem tts!", doesThrow(() -> {
|
||||||
InputStream inputStream = ElevenLabs.generateTextToSpeechStreamed(TEST_VOICE, "This is a test", "eleven_monolingual_v1", new VoiceSettings(0.7, 0.7));
|
InputStream inputStream = ElevenLabs.generateTextToSpeechStreamed(TEST_VOICE, "This is a test", "eleven_monolingual_v1", new VoiceSettings(0.7, 0.7, 0, true));
|
||||||
File tmp;
|
File tmp;
|
||||||
try {
|
try {
|
||||||
tmp = File.createTempFile("test", "audio");
|
tmp = File.createTempFile("test", "audio");
|
||||||
|
|||||||
Reference in New Issue
Block a user