mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-05-06 03:00:23 -04:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
388d059af7 | ||
|
|
1f9c48eac6 | ||
|
|
b3ea0e2a09 | ||
|
|
75eb64a077 | ||
|
|
c5706317aa | ||
|
|
0a2f6d1869 | ||
|
|
b753769a53 | ||
|
|
8162cada71 | ||
|
|
fdcc12ee41 | ||
|
|
8c526a1539 | ||
|
|
95cf38c620 | ||
|
|
6968219c55 | ||
|
|
e6279b689f | ||
|
|
3462385f3d |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Dev Build
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
116
README.md
116
README.md
@@ -4,15 +4,19 @@
|
||||
## Getting Started
|
||||
So you wanna make custom voices, huh? Well you've come to the right place.
|
||||
|
||||
### Note: This repo is undergoing an upgrade to v2.0
|
||||
If any of the documentation is out of place or issues occur, please submit a PR or create an issue.
|
||||
I downgraded the repo from JDK 17 to JDK 11 as well.
|
||||
|
||||
### Installation
|
||||
**Maven**
|
||||
|
||||
To add `elevenlabs-api` to your Maven project, use:
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>net.andrewcpu.elevenlabs</groupId>
|
||||
<groupId>net.andrewcpu</groupId>
|
||||
<artifactId>elevenlabs-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
```
|
||||
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 set up your ElevenLabs API key, you must register it with the ElevenLabsAPI Java API like below:
|
||||
```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.*
|
||||
|
||||
Once you've injected your API Key, you can safely assume that you will not receive a `ElevenLabsAPINotInitiatedException`.
|
||||
- - -
|
||||
|
||||
<!-- TOC -->
|
||||
@@ -66,9 +69,6 @@ Once you've injected your API Key, you can safely assume that you will not recei
|
||||
* [Exceptions](#exceptions)
|
||||
* [*ElevenLabsAPINotInitiatedException*](#elevenlabsapinotinitiatedexception)
|
||||
* [*ElevenLabsValidationException*](#elevenlabsvalidationexception)
|
||||
* [Built in Types](#built-in-types)
|
||||
* [`Voice` Related Types](#voice-related-types)
|
||||
* [`User` Related Types](#user-related-types)
|
||||
* [Misc](#misc)
|
||||
|
||||
* [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`.
|
||||
```java
|
||||
Voice voice;
|
||||
File outputFile = voice.generate(String text, VoiceSettings voiceSettings, File output);
|
||||
File outputFile = voice.generate(String text, File output); // Uses default voice settings
|
||||
File file = voice.generate(String text);
|
||||
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.
|
||||
```java
|
||||
Voice voice;
|
||||
File file = voice.getSamples().get(0).downloadAudio(File outputFile);
|
||||
File file = voice.getSamples().get(0).downloadAudio();
|
||||
```
|
||||
|
||||
### Deleting a Sample
|
||||
@@ -214,11 +221,11 @@ 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<HistoryItem>` parameter.
|
||||
The second parameter is the path in which you would like to save the ZIP file.
|
||||
|
||||
```java
|
||||
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);
|
||||
File download = history.downloadHistory(new String[]{"item-id1", "item-id2"});
|
||||
File download = history.downloadHistory(List<HistoryItem> historyItems);
|
||||
```
|
||||
|
||||
### Deleting a HistoryItem
|
||||
@@ -236,10 +243,10 @@ 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.
|
||||
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
|
||||
HistoryItem item;
|
||||
File file = item.downloadAudio(File outputFile);
|
||||
File file = item.downloadAudio();
|
||||
```
|
||||
- - -
|
||||
|
||||
@@ -259,77 +266,8 @@ User user = User.get();
|
||||
|
||||
- - -
|
||||
## 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*
|
||||
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
|
||||
*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 🥂
|
||||
|
||||
95
pom.xml
95
pom.xml
@@ -6,6 +6,7 @@
|
||||
|
||||
<name>Unofficial Java ElevenLabs Voice API</name>
|
||||
<description>An API level interaction between Java and the ElevenLabs Voice Generation Web API.</description>
|
||||
<url>https://github.com/AndrewCPU/elevenlabs-api</url>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>Andrewcpu</id>
|
||||
@@ -24,17 +25,42 @@
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>github</id>
|
||||
<name>GitHub AndrewCPU Apache Maven Packages</name>
|
||||
<url>https://maven.pkg.github.com/AndrewCPU/elevenlabs-api</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<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>
|
||||
<artifactId>elevenlabs-api</artifactId>
|
||||
<version>2.0-SNAPSHOT</version>
|
||||
<version>2.2</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
@@ -94,6 +120,20 @@
|
||||
<build>
|
||||
<finalName>elevenlabs-api-${version}</finalName>
|
||||
<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>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
@@ -114,6 +154,47 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</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>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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.HistoryItem;
|
||||
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.voice.Voice;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.net.ElevenRequest;
|
||||
import net.andrewcpu.elevenlabs.net.history.*;
|
||||
import net.andrewcpu.elevenlabs.net.models.GetModelsRequest;
|
||||
import net.andrewcpu.elevenlabs.net.samples.DeleteSampleRequest;
|
||||
import net.andrewcpu.elevenlabs.net.samples.GetSampleRequest;
|
||||
import net.andrewcpu.elevenlabs.net.tts.PostTextToSpeechRequest;
|
||||
import net.andrewcpu.elevenlabs.net.tts.PostTextToSpeechStreamedRequest;
|
||||
import net.andrewcpu.elevenlabs.net.user.GetSubscriptionRequest;
|
||||
import net.andrewcpu.elevenlabs.net.user.GetUserRequest;
|
||||
import net.andrewcpu.elevenlabs.net.voices.*;
|
||||
import net.andrewcpu.elevenlabs.requests.ElevenLabsRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.history.*;
|
||||
import net.andrewcpu.elevenlabs.requests.models.GetModelsRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.samples.DeleteSampleRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.samples.GetSampleRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechStreamedRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.user.GetSubscriptionRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.user.GetUserRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.voices.*;
|
||||
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
||||
|
||||
import java.io.File;
|
||||
@@ -37,7 +39,7 @@ public class ElevenLabs {
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -120,6 +122,13 @@ public class ElevenLabs {
|
||||
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) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,19 @@ package net.andrewcpu.elevenlabs.model.history;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class History extends ElevenModel {
|
||||
|
||||
public static History get() {
|
||||
return ElevenLabs.getHistory();
|
||||
}
|
||||
|
||||
@JsonProperty("history")
|
||||
private List<HistoryItem> historyItems;
|
||||
|
||||
@@ -23,6 +31,16 @@ public class History extends ElevenModel {
|
||||
public History() {
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public HistoryItem getHistoryItem(String id) {
|
||||
for (HistoryItem item : historyItems) {
|
||||
if (item.getHistoryItemId().equals(id)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public List<HistoryItem> getHistoryItems() {
|
||||
return historyItems;
|
||||
@@ -38,6 +56,14 @@ public class History extends ElevenModel {
|
||||
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
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -2,8 +2,10 @@ package net.andrewcpu.elevenlabs.model.history;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class HistoryItem extends ElevenModel {
|
||||
@@ -121,6 +123,14 @@ public class HistoryItem extends ElevenModel {
|
||||
return feedback;
|
||||
}
|
||||
|
||||
public String delete() {
|
||||
return ElevenLabs.deleteHistoryItem(historyItemId);
|
||||
}
|
||||
|
||||
public File downloadAudio() {
|
||||
return ElevenLabs.getHistoryItemAudio(historyItemId);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -24,23 +24,46 @@ public class GenerationTypeModel extends ElevenModel {
|
||||
@JsonProperty("can_do_voice_conversion")
|
||||
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")
|
||||
private int tokenCostFactor;
|
||||
|
||||
@JsonProperty("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")
|
||||
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.name = name;
|
||||
this.canBeFinetuned = canBeFinetuned;
|
||||
this.canDoTextToSpeech = canDoTextToSpeech;
|
||||
this.canDoVoiceConversion = canDoVoiceConversion;
|
||||
this.canUseStyle = canUseStyle;
|
||||
this.canUseSpeakerBoost = canUseSpeakerBoost;
|
||||
this.servesProVoices = servesProVoices;
|
||||
this.tokenCostFactor = tokenCostFactor;
|
||||
this.description = description;
|
||||
this.requiresAlphaAccess = requiresAlphaAccess;
|
||||
this.maxCharactersRequestFreeUser = maxCharactersRequestFreeUser;
|
||||
this.maxCharactersRequestSubscribedUser = maxCharactersRequestSubscribedUser;
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
@@ -87,17 +110,54 @@ public class GenerationTypeModel extends ElevenModel {
|
||||
return languages;
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
@JsonIgnore
|
||||
public String toString() {
|
||||
return "ModelResponse{" +
|
||||
return "GenerationTypeModel{" +
|
||||
"modelId='" + modelId + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", canBeFinetuned=" + canBeFinetuned +
|
||||
", canDoTextToSpeech=" + canDoTextToSpeech +
|
||||
", canDoVoiceConversion=" + canDoVoiceConversion +
|
||||
", canUseStyle=" + canUseStyle +
|
||||
", canUseSpeakerBoost=" + canUseSpeakerBoost +
|
||||
", servesProVoices=" + servesProVoices +
|
||||
", tokenCostFactor=" + tokenCostFactor +
|
||||
", description='" + description + '\'' +
|
||||
", requiresAlphaAccess=" + requiresAlphaAccess +
|
||||
", maxCharactersRequestFreeUser=" + maxCharactersRequestFreeUser +
|
||||
", maxCharactersRequestSubscribedUser=" + maxCharactersRequestSubscribedUser +
|
||||
", languages=" + languages +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -2,9 +2,15 @@ package net.andrewcpu.elevenlabs.model.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
public class Subscription extends ElevenModel {
|
||||
@JsonIgnore
|
||||
public static Subscription get() {
|
||||
return ElevenLabs.getSubscription();
|
||||
}
|
||||
|
||||
@JsonProperty("tier")
|
||||
private String tier;
|
||||
|
||||
|
||||
@@ -2,9 +2,15 @@ package net.andrewcpu.elevenlabs.model.user;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
public class User extends ElevenModel {
|
||||
|
||||
public static User get() {
|
||||
return ElevenLabs.getUser();
|
||||
}
|
||||
|
||||
@JsonProperty("subscription")
|
||||
private Subscription subscription;
|
||||
|
||||
|
||||
@@ -2,8 +2,11 @@ package net.andrewcpu.elevenlabs.model.voice;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Sample extends ElevenModel {
|
||||
@JsonProperty("sample_id")
|
||||
private String sampleId;
|
||||
@@ -20,6 +23,9 @@ public class Sample extends ElevenModel {
|
||||
@JsonProperty("hash")
|
||||
private String hash;
|
||||
|
||||
@JsonIgnore
|
||||
public Voice voice;
|
||||
|
||||
public Sample(String sampleId, String fileName, String mimeType, long sizeBytes, String hash) {
|
||||
this.sampleId = sampleId;
|
||||
this.fileName = fileName;
|
||||
@@ -56,6 +62,17 @@ public class Sample extends ElevenModel {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public File downloadAudio() {
|
||||
return ElevenLabs.getAudioSample(voice.getVoiceId(), sampleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning! This will delete the sample.
|
||||
*/
|
||||
public String delete() {
|
||||
return ElevenLabs.deleteSample(voice.getVoiceId(), sampleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String toString() {
|
||||
|
||||
@@ -2,13 +2,31 @@ package net.andrewcpu.elevenlabs.model.voice;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
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.tuning.FineTuning;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Voice extends ElevenModel {
|
||||
public static List<Voice> getVoices() {
|
||||
return ElevenLabs.getVoices();
|
||||
}
|
||||
|
||||
public static Voice getVoice(String voiceId) {
|
||||
return ElevenLabs.getVoice(voiceId);
|
||||
}
|
||||
|
||||
public static Voice getVoice(String voiceId, boolean withSettings) {
|
||||
return ElevenLabs.getVoice(voiceId, withSettings);
|
||||
}
|
||||
|
||||
@JsonProperty("voice_id")
|
||||
private String voiceId;
|
||||
|
||||
@@ -42,6 +60,9 @@ public class Voice extends ElevenModel {
|
||||
@JsonProperty("sharing")
|
||||
private Sharing sharing;
|
||||
|
||||
@JsonProperty("high_quality_base_model_ids")
|
||||
private List<String> highQualityBaseModelIds;
|
||||
|
||||
@JsonIgnore
|
||||
public String getVoiceId() {
|
||||
return voiceId;
|
||||
@@ -54,7 +75,7 @@ public class Voice extends ElevenModel {
|
||||
|
||||
@JsonIgnore
|
||||
public List<Sample> getSamples() {
|
||||
return samples;
|
||||
return samples.stream().peek(s -> s.voice = this).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@@ -97,8 +118,136 @@ public class Voice extends ElevenModel {
|
||||
return sharing;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
/**
|
||||
* Warning! This will delete the voice.
|
||||
*/
|
||||
public String delete() {
|
||||
return ElevenLabs.deleteVoice(voiceId);
|
||||
}
|
||||
public VoiceSettings fetchSettings() {
|
||||
this.settings = ElevenLabs.getVoiceSettings(voiceId);
|
||||
return settings;
|
||||
}
|
||||
|
||||
public VoiceSettings updateVoiceSettings(VoiceSettings voiceSettings) {
|
||||
ElevenLabs.editVoiceSettings(voiceId, voiceSettings);
|
||||
this.settings = voiceSettings;
|
||||
return settings;
|
||||
}
|
||||
|
||||
public Voice refresh() {
|
||||
Voice refreshedData = Voice.getVoice(voiceId, true);
|
||||
this.name = refreshedData.name;
|
||||
this.settings = refreshedData.settings;
|
||||
this.voiceId = refreshedData.voiceId;
|
||||
this.labels = refreshedData.labels;
|
||||
this.description = refreshedData.description;
|
||||
this.samples = refreshedData.samples;
|
||||
this.fineTuning = refreshedData.fineTuning;
|
||||
this.availableForTiers = refreshedData.availableForTiers;
|
||||
this.sharing = refreshedData.sharing;
|
||||
this.previewUrl = refreshedData.previewUrl;
|
||||
this.category = refreshedData.category;
|
||||
this.highQualityBaseModelIds = refreshedData.highQualityBaseModelIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
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
|
||||
@JsonIgnore
|
||||
public String toString() {
|
||||
return "Voice{" +
|
||||
"voiceId='" + voiceId + '\'' +
|
||||
@@ -112,6 +261,7 @@ public class Voice extends ElevenModel {
|
||||
", availableForTiers=" + availableForTiers +
|
||||
", settings=" + settings +
|
||||
", sharing=" + sharing +
|
||||
", highQualityBaseModelIds=" + highQualityBaseModelIds +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package net.andrewcpu.elevenlabs.model.voice;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class VoiceBuilder {
|
||||
public static VoiceBuilder fromVoice(Voice voice) {
|
||||
VoiceBuilder voiceBuilder = new VoiceBuilder(voice);
|
||||
return voiceBuilder;
|
||||
}
|
||||
|
||||
private Voice voice;
|
||||
private String name;
|
||||
private String description;
|
||||
private Map<String, String> labels;
|
||||
private List<File> files;
|
||||
|
||||
public VoiceBuilder() {
|
||||
this.labels = new HashMap<>();
|
||||
this.files = new ArrayList<>();
|
||||
}
|
||||
|
||||
public VoiceBuilder(Voice voice) {
|
||||
this();
|
||||
this.voice = voice;
|
||||
this.name = voice.getName();
|
||||
this.description = voice.getDescription();
|
||||
this.labels = voice.getLabels();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public VoiceBuilder withName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public VoiceBuilder withDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public VoiceBuilder withLabels(Map<String, String> labels) {
|
||||
this.labels = labels;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VoiceBuilder withLabel(String key, String value) {
|
||||
this.labels.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<File> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
public VoiceBuilder withFile(File file) {
|
||||
this.files.add(file);
|
||||
return this;
|
||||
}
|
||||
|
||||
public VoiceBuilder withFiles(List<File> files) {
|
||||
this.files = files;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Voice create() {
|
||||
CreateVoiceResponse createVoiceResponse = ElevenLabs.createVoice(name, files.toArray(File[]::new), description, labels);
|
||||
return Voice.getVoice(createVoiceResponse.getVoiceId(), true);
|
||||
}
|
||||
|
||||
public Voice edit() {
|
||||
ElevenLabs.editVoice(voice.getVoiceId(), name, files.toArray(File[]::new), description, labels);
|
||||
voice = voice.refresh();
|
||||
return voice;
|
||||
}
|
||||
}
|
||||
@@ -2,18 +2,37 @@ package net.andrewcpu.elevenlabs.model.voice;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
|
||||
public class VoiceSettings extends ElevenModel {
|
||||
public static VoiceSettings getDefaultVoiceSettings() {
|
||||
return ElevenLabs.getDefaultVoiceSettings();
|
||||
}
|
||||
@JsonProperty("stability")
|
||||
private double stability;
|
||||
|
||||
@JsonProperty("similarity_boost")
|
||||
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) {
|
||||
this.stability = stability;
|
||||
this.similarityBoost = similarityBoost;
|
||||
this.style = 0;
|
||||
this.useSpeakerBoost = true;
|
||||
}
|
||||
|
||||
public VoiceSettings() {
|
||||
@@ -30,11 +49,23 @@ public class VoiceSettings extends ElevenModel {
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public double getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isUseSpeakerBoost() {
|
||||
return useSpeakerBoost;
|
||||
}
|
||||
|
||||
@Override
|
||||
@JsonIgnore
|
||||
public String toString() {
|
||||
return "VoiceSettings{" +
|
||||
"stability=" + stability +
|
||||
", 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 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;
|
||||
|
||||
@@ -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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetHistoryItemByIdRequest extends GetRequest<HistoryItem> {
|
||||
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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetHistoryRequest extends GetRequest<History> {
|
||||
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.net.PostRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetModelsRequest extends GetRequest<GenerationTypeModel[]> {
|
||||
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 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;
|
||||
|
||||
@@ -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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetUserRequest extends GetRequest<User> {
|
||||
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 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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetDefaultVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
||||
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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
||||
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.net.GetRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetVoicesRequest extends GetRequest<VoiceModelResponse> {
|
||||
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.net.PostRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
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.net.PostRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
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.net.PostRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
public class PostEditVoiceSettingsRequest extends PostRequest<String> {
|
||||
private VoiceSettings voiceSettings;
|
||||
@@ -3,12 +3,10 @@ package net.andrewcpu.elevenlabs.util;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.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.entity.UrlEncodedFormEntity;
|
||||
import org.apache.hc.client5.http.entity.mime.FileBody;
|
||||
import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder;
|
||||
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.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.interfaces.DSAParams;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class ElevenNetworkUtil {
|
||||
private static final String BASE_URL = "https://api.elevenlabs.io/";
|
||||
@@ -38,6 +36,23 @@ public class ElevenNetworkUtil {
|
||||
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) {
|
||||
switch (type) {
|
||||
@@ -141,6 +156,7 @@ public class ElevenNetworkUtil {
|
||||
try {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
HttpUriRequestBase request = getRequest(method, path, payload);
|
||||
|
||||
return getRequestResult(responseType, objectMapper, httpclient, request);
|
||||
} catch (IOException | ValidationException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -2,7 +2,7 @@ package net.andrewcpu.elevenlabs;
|
||||
|
||||
|
||||
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";
|
||||
static {
|
||||
ElevenLabs.setApiKey(ELEVEN_LABS_API_KEY);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class TextToSpeechTest extends ElevenLabsTest {
|
||||
@Test
|
||||
public void testDownloadResponse() {
|
||||
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();
|
||||
}));
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class TextToSpeechTest extends ElevenLabsTest {
|
||||
@Test
|
||||
public void testStreamedResponse() {
|
||||
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;
|
||||
try {
|
||||
tmp = File.createTempFile("test", "audio");
|
||||
|
||||
Reference in New Issue
Block a user