mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-05-06 03:00:23 -04:00
Compare commits
24 Commits
v57
...
15-multipl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa4c8bf5db | ||
|
|
96fc45920d | ||
|
|
b9c74c1bd7 | ||
|
|
f2f3915c6c | ||
|
|
79e570f989 | ||
|
|
0a4a221b5c | ||
|
|
cc360a258e | ||
|
|
9c7fffbb9a | ||
|
|
4cfd14fb95 | ||
|
|
a8630ceeb0 | ||
|
|
7593f3a3f1 | ||
|
|
5288fde44e | ||
|
|
ce86914f71 | ||
|
|
4a212c7721 | ||
|
|
f46bb6878e | ||
|
|
81cdf05152 | ||
|
|
6e5ae633a6 | ||
|
|
a6163fd67f | ||
|
|
26a4ab1fa4 | ||
|
|
72f35c14b7 | ||
|
|
90a092aa81 | ||
|
|
02d7ec0685 | ||
|
|
75f1c40f59 | ||
|
|
3ac42a330b |
152
README.md
152
README.md
@@ -3,10 +3,9 @@
|
||||
|
||||
## Getting Started
|
||||
So you wanna make custom voices, huh? Well you've come to the right place.
|
||||
|
||||
### Note: This repo is undergoing an upgrade to v2.0
|
||||
If any of the documentation is out of place or issues occur, please submit a PR or create an issue.
|
||||
I downgraded the repo from JDK 17 to JDK 11 as well.
|
||||
This library should cover all the ElevenLabs API endpoints as of 11/15/23.
|
||||
**Update**
|
||||
It seems I jumped the gun (or happened to bump into an accidental push of the speech to speech API docs), but the original documentation that my implementation was based on has now been removed or hidden. It may reappear as is, or will require changes.
|
||||
|
||||
### Installation
|
||||
**Maven**
|
||||
@@ -16,12 +15,9 @@ To add `elevenlabs-api` to your Maven project, use:
|
||||
<dependency>
|
||||
<groupId>net.andrewcpu</groupId>
|
||||
<artifactId>elevenlabs-api</artifactId>
|
||||
<version>2.7</version>
|
||||
<version>2.7.8</version>
|
||||
</dependency>
|
||||
```
|
||||
The most up-to date package information can be found on the [Packages tab](https://github.com/AndrewCPU/elevenlabs-api/packages/)
|
||||
|
||||
|
||||
**JAR**
|
||||
|
||||
Compiled JARs are available via the [Releases tab](https://github.com/AndrewCPU/elevenlabs-api/releases)
|
||||
@@ -32,6 +28,9 @@ To access your ElevenLabs API key, head to the [official website](https://eleven
|
||||
To set up your ElevenLabs API key, you must register it with the ElevenLabsAPI Java API like below:
|
||||
```java
|
||||
ElevenLabs.setApiKey("YOUR_API_KEY_HERE");
|
||||
|
||||
|
||||
ElevenLabs.setDefaultModel("eleven_monolingual_v1"); // Optional, defaults to: "eleven_monolingual_v1"
|
||||
```
|
||||
*For any public repository security, you should store your API key in an environment variable, or external from your source code.*
|
||||
|
||||
@@ -41,6 +40,94 @@ ElevenLabs.setApiKey("YOUR_API_KEY_HERE");
|
||||
### **ElevenLabs API Documentation**: https://api.elevenlabs.io/docs
|
||||
|
||||
- - -
|
||||
|
||||
## Simplified Generation Handling with Builders
|
||||
### v2.7.8 now includes SpeechGenerationBuilder.java
|
||||
|
||||
[//]: # (### Speech to Speech)
|
||||
|
||||
[//]: # (```java)
|
||||
|
||||
[//]: # (//File output)
|
||||
|
||||
[//]: # (SpeechGenerationBuilder.speechToSpeech())
|
||||
|
||||
[//]: # ( .file() // output type of file (or use .streamed() for an InputStream))
|
||||
|
||||
[//]: # ( .setInputFile(File))
|
||||
|
||||
[//]: # ( .setGeneratedAudioOutputFormat(GeneratedAudioOutputFormat.MP3_44100_128))
|
||||
|
||||
[//]: # ( .setVoiceId("voiceIdString"))
|
||||
|
||||
[//]: # ( .setVoiceSettings(VoiceSettings))
|
||||
|
||||
[//]: # ( .setVoice(Voice) // or use a voice object, which will pull settings / ID out of the Voice)
|
||||
|
||||
[//]: # ( .setModelId("modelIdString"))
|
||||
|
||||
[//]: # ( .setModel(ElevenLabsVoiceModel.ELEVEN_ENGLISH_STS_V2))
|
||||
|
||||
[//]: # ( .setLatencyOptimization(StreamLatencyOptimization.NONE))
|
||||
|
||||
[//]: # ( .build();)
|
||||
|
||||
[//]: # (//Streamed output)
|
||||
|
||||
[//]: # (SpeechGenerationBuilder.speechToSpeech())
|
||||
|
||||
[//]: # ( .streamed())
|
||||
|
||||
[//]: # ( .setInputFile(File))
|
||||
|
||||
[//]: # ( .setGeneratedAudioOutputFormat(GeneratedAudioOutputFormat.MP3_44100_128))
|
||||
|
||||
[//]: # ( .setVoiceId("voiceIdString"))
|
||||
|
||||
[//]: # ( .setVoiceSettings(VoiceSettings))
|
||||
|
||||
[//]: # ( .setVoice(Voice) // or use a voice object, which will pull settings / ID out of the Voice)
|
||||
|
||||
[//]: # ( .setModelId("modelIdString"))
|
||||
|
||||
[//]: # ( .setModel(ElevenLabsVoiceModel.ELEVEN_ENGLISH_STS_V2))
|
||||
|
||||
[//]: # ( .setLatencyOptimization(StreamLatencyOptimization.NONE))
|
||||
|
||||
[//]: # ( .build();)
|
||||
|
||||
[//]: # (```)
|
||||
|
||||
### Text to Speech
|
||||
```java
|
||||
//File output
|
||||
SpeechGenerationBuilder.textToSpeech()
|
||||
.file() // output type of file (or use .streamed() for an InputStream)
|
||||
.setText(String text)
|
||||
.setGeneratedAudioOutputFormat(GeneratedAudioOutputFormat.MP3_44100_128)
|
||||
.setVoiceId("voiceIdString")
|
||||
.setVoiceSettings(VoiceSettings)
|
||||
.setVoice(Voice) // or use a voice object, which will pull settings / ID out of the Voice
|
||||
.setModelId("modelIdString")
|
||||
.setModel(ElevenLabsVoiceModel.ELEVEN_ENGLISH_STS_V2)
|
||||
.setLatencyOptimization(StreamLatencyOptimization.NONE)
|
||||
.build();
|
||||
//Streamed output
|
||||
SpeechGenerationBuilder.textToSpeech()
|
||||
.streamed()
|
||||
.setText(String text)
|
||||
.setGeneratedAudioOutputFormat(GeneratedAudioOutputFormat.MP3_44100_128)
|
||||
.setVoiceId("voiceIdString")
|
||||
.setVoiceSettings(VoiceSettings)
|
||||
.setVoice(Voice) // or use a voice object, which will pull settings / ID out of the Voice
|
||||
.setModelId("modelIdString")
|
||||
.setModel(ElevenLabsVoiceModel.ELEVEN_ENGLISH_STS_V2)
|
||||
.setLatencyOptimization(StreamLatencyOptimization.NONE)
|
||||
.build();
|
||||
```
|
||||
|
||||
- - -
|
||||
|
||||
## Voices
|
||||
### Accessing your List of Available Voices
|
||||
To retrieve your list of accessible Voices, you can statically utilize `Voice#getVoices()`. This will return both ElevenLab's pregenerated `Voice` models, as well as any personal `Voices` you have generated.
|
||||
@@ -179,19 +266,26 @@ public InputStream generateStream(String text, VoiceSettings settings, StreamLat
|
||||
|
||||
public InputStream generateStream(String text, StreamLatencyOptimization streamLatencyOptimization);
|
||||
|
||||
public File speechToSpeech(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId, VoiceSettings voiceSettings);
|
||||
|
||||
public File speechToSpeech(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId);
|
||||
|
||||
public File speechToSpeech(File audioFile, String modelId);
|
||||
|
||||
public InputStream speechToSpeechStream(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId, VoiceSettings voiceSettings);
|
||||
|
||||
public InputStream speechToSpeechStream(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId);
|
||||
|
||||
public InputStream speechToSpeechStream(File audioFile, String modelId);
|
||||
|
||||
```
|
||||
|
||||
[//]: # (public File speechToSpeech(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId, VoiceSettings voiceSettings);)
|
||||
|
||||
[//]: # ()
|
||||
[//]: # (public File speechToSpeech(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId);)
|
||||
|
||||
[//]: # ()
|
||||
[//]: # (public File speechToSpeech(File audioFile, String modelId);)
|
||||
|
||||
[//]: # ()
|
||||
[//]: # (public InputStream speechToSpeechStream(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId, VoiceSettings voiceSettings);)
|
||||
|
||||
[//]: # ()
|
||||
[//]: # (public InputStream speechToSpeechStream(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId);)
|
||||
|
||||
[//]: # ()
|
||||
[//]: # (public InputStream speechToSpeechStream(File audioFile, String modelId);)
|
||||
|
||||
|
||||
- - -
|
||||
## Audio Native Projects
|
||||
### Creating an Audio Native Project
|
||||
@@ -350,6 +444,19 @@ To get your ElevenLabs generation `History`, you can utilize `History#get()`. (Y
|
||||
History history = History.get();
|
||||
```
|
||||
|
||||
|
||||
### Getting all History Items
|
||||
The History endpoint accepts page size parameters and a start-after-history-id parameter. We can use this to fetch all of our HistoryItems.
|
||||
```java
|
||||
History history = History.get(); // the latest history object
|
||||
Optional<History> hist = Optional.of(history);
|
||||
List<HistoryItem> items = new ArrayList();
|
||||
do {
|
||||
items.addAll(hist.get().getHistoryItems());
|
||||
hist = hist.get().next();
|
||||
} while(hist.isPresent() && hist.hasMore());
|
||||
```
|
||||
|
||||
### Getting a History Item
|
||||
To retrieve a `HistoryItem` from your `History`, you can use `History#getHistoryItem(String itemId)`.
|
||||
```java
|
||||
@@ -420,6 +527,11 @@ If you like what you see, give it a star! :)
|
||||
|
||||
- - -
|
||||
|
||||
## Todo
|
||||
I will probably rework the 2 new builders I added when I added projects support. Their usage should be more clear, though the documentation covers their use cases I believe.
|
||||
|
||||
- - -
|
||||
|
||||
#### Unit Testing
|
||||
Unit tests have been created, these endpoints are destructive and not included in the testing:
|
||||
* deleteHistoryItem - WONT TEST
|
||||
|
||||
9
pom.xml
9
pom.xml
@@ -60,7 +60,7 @@
|
||||
|
||||
<groupId>net.andrewcpu</groupId>
|
||||
<artifactId>elevenlabs-api</artifactId>
|
||||
<version>2.7-SNAPSHOT</version>
|
||||
<version>2.7.8</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
@@ -80,17 +80,17 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.13.4.1</version>
|
||||
<version>2.15.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.13.4</version>
|
||||
<version>2.15.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.13.4</version>
|
||||
<version>2.15.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -194,7 +194,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import net.andrewcpu.elevenlabs.api.impl.*;
|
||||
|
||||
public class ElevenLabs {
|
||||
@@ -17,6 +18,15 @@ public class ElevenLabs {
|
||||
public static String getApiKey() {
|
||||
return API_KEY;
|
||||
}
|
||||
private static String defaultModel = "eleven_monolingual_v1";
|
||||
|
||||
public static String getDefaultModel() {
|
||||
return defaultModel;
|
||||
}
|
||||
|
||||
public static void setDefaultModel(String defaultModel) {
|
||||
ElevenLabs.defaultModel = defaultModel;
|
||||
}
|
||||
|
||||
public static void setApiKey(String apiKey) {
|
||||
API_KEY = apiKey;
|
||||
|
||||
@@ -13,6 +13,14 @@ public class HistoryAPI extends ElevenLabsAPI {
|
||||
return sendRequest(new GetHistoryRequest());
|
||||
}
|
||||
|
||||
public History getHistory(int pageSize, String afterHistoryId) {
|
||||
return sendRequest(new GetHistoryRequest(pageSize, afterHistoryId));
|
||||
}
|
||||
|
||||
public History getHistory(String afterHistoryId) {
|
||||
return sendRequest(new GetHistoryRequest(afterHistoryId));
|
||||
}
|
||||
|
||||
public HistoryItem getHistoryItem(String historyItemId) {
|
||||
return sendRequest(new GetHistoryItemByIdRequest(historyItemId));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.api.impl;
|
||||
|
||||
import net.andrewcpu.elevenlabs.api.ElevenLabsAPI;
|
||||
import net.andrewcpu.elevenlabs.enums.ElevenLabsVoiceModel;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.sts.PostSpeechToSpeechRequest;
|
||||
@@ -25,4 +26,22 @@ public class SpeechToSpeechAPI extends ElevenLabsAPI {
|
||||
public InputStream generateSpeechToSpeechStream(String voiceId, VoiceSettings voiceSettings, String modelId, File audio) {
|
||||
return generateSpeechToSpeechStream(voiceId, voiceSettings, modelId, audio, StreamLatencyOptimization.getDefault());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public File generateSpeechToSpeech(String voiceId, VoiceSettings voiceSettings, ElevenLabsVoiceModel model, File audio) {
|
||||
return generateSpeechToSpeech(voiceId, voiceSettings, model.getModelId(), audio, StreamLatencyOptimization.getDefault());
|
||||
}
|
||||
|
||||
public File generateSpeechToSpeech(String voiceId, VoiceSettings voiceSettings, ElevenLabsVoiceModel model, File audio, StreamLatencyOptimization latencyOptimization) {
|
||||
return sendRequest(new PostSpeechToSpeechRequest(voiceId, voiceSettings,audio, model.getModelId(), latencyOptimization));
|
||||
}
|
||||
|
||||
public InputStream generateSpeechToSpeechStream(String voiceId, VoiceSettings voiceSettings, ElevenLabsVoiceModel model, File audio, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return sendRequest(new PostSpeechToSpeechStreamedRequest(voiceId, voiceSettings, audio, model.getModelId(), streamLatencyOptimization));
|
||||
}
|
||||
|
||||
public InputStream generateSpeechToSpeechStream(String voiceId, VoiceSettings voiceSettings, ElevenLabsVoiceModel model, File audio) {
|
||||
return generateSpeechToSpeechStream(voiceId, voiceSettings, model.getModelId(), audio, StreamLatencyOptimization.getDefault());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.andrewcpu.elevenlabs.builders;
|
||||
|
||||
public class SpeechGenerationBuilder {
|
||||
public static SpeechToSpeechBuilder speechToSpeech() {
|
||||
return new SpeechToSpeechBuilder();
|
||||
}
|
||||
|
||||
public static TextToSpeechBuilder textToSpeech() {
|
||||
return new TextToSpeechBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.andrewcpu.elevenlabs.builders;
|
||||
|
||||
import net.andrewcpu.elevenlabs.builders.impl.s2s.SpeechToSpeechFileBuilder;
|
||||
import net.andrewcpu.elevenlabs.builders.impl.s2s.SpeechToSpeechStreamedBuilder;
|
||||
|
||||
public class SpeechToSpeechBuilder {
|
||||
|
||||
public SpeechToSpeechStreamedBuilder streamed() {
|
||||
return new SpeechToSpeechStreamedBuilder();
|
||||
}
|
||||
|
||||
public SpeechToSpeechFileBuilder file() {
|
||||
return new SpeechToSpeechFileBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package net.andrewcpu.elevenlabs.builders;
|
||||
|
||||
|
||||
import net.andrewcpu.elevenlabs.builders.impl.tts.TextToSpeechFileBuilder;
|
||||
import net.andrewcpu.elevenlabs.builders.impl.tts.TextToSpeechStreamedBuilder;
|
||||
|
||||
public class TextToSpeechBuilder {
|
||||
public TextToSpeechStreamedBuilder streamed() {
|
||||
return new TextToSpeechStreamedBuilder();
|
||||
}
|
||||
|
||||
public TextToSpeechFileBuilder file() {
|
||||
return new TextToSpeechFileBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package net.andrewcpu.elevenlabs.builders.abstracts;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.builders.SpeechToSpeechBuilder;
|
||||
import net.andrewcpu.elevenlabs.builders.TextToSpeechBuilder;
|
||||
import net.andrewcpu.elevenlabs.enums.ElevenLabsVoiceModel;
|
||||
import net.andrewcpu.elevenlabs.enums.GeneratedAudioOutputFormat;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.voice.Voice;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
|
||||
public abstract class AbstractSpeechGenerationBuilder<T, F> {
|
||||
private String voiceId;
|
||||
private VoiceSettings voiceSettings;
|
||||
private String modelId = ElevenLabs.getDefaultModel();
|
||||
private StreamLatencyOptimization latencyOptimization = StreamLatencyOptimization.getDefault();
|
||||
private GeneratedAudioOutputFormat generatedAudioOutputFormat = GeneratedAudioOutputFormat.getDefault();
|
||||
public abstract T self();
|
||||
|
||||
public abstract F build();
|
||||
|
||||
|
||||
public GeneratedAudioOutputFormat getGeneratedAudioOutputFormat() {
|
||||
return generatedAudioOutputFormat;
|
||||
}
|
||||
|
||||
public T setGeneratedAudioOutputFormat(GeneratedAudioOutputFormat generatedAudioOutputFormat) {
|
||||
this.generatedAudioOutputFormat = generatedAudioOutputFormat;
|
||||
return self();
|
||||
}
|
||||
|
||||
public String getVoiceId() {
|
||||
return voiceId;
|
||||
}
|
||||
|
||||
public T setVoiceId(String voiceId) {
|
||||
this.voiceId = voiceId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public VoiceSettings getVoiceSettings() {
|
||||
return voiceSettings;
|
||||
}
|
||||
|
||||
public T setVoiceSettings(VoiceSettings voiceSettings) {
|
||||
this.voiceSettings = voiceSettings;
|
||||
return self();
|
||||
}
|
||||
|
||||
public String getModelId() {
|
||||
return modelId;
|
||||
}
|
||||
|
||||
public T setModelId(String modelId) {
|
||||
this.modelId = modelId;
|
||||
return self();
|
||||
}
|
||||
|
||||
public StreamLatencyOptimization getLatencyOptimization() {
|
||||
return latencyOptimization;
|
||||
}
|
||||
|
||||
public T setLatencyOptimization(StreamLatencyOptimization latencyOptimization) {
|
||||
this.latencyOptimization = latencyOptimization;
|
||||
return self();
|
||||
}
|
||||
|
||||
public T setVoice(Voice voice) {
|
||||
this.voiceId = voice.getVoiceId();
|
||||
if(voice.getSettings() == null) voice.fetchSettings();
|
||||
this.voiceSettings = voice.getSettings();
|
||||
return self();
|
||||
}
|
||||
|
||||
public T setModel(ElevenLabsVoiceModel voiceModel) {
|
||||
this.modelId = voiceModel.getModelId();
|
||||
return self();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.andrewcpu.elevenlabs.builders.impl.s2s;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.builders.abstracts.AbstractSpeechGenerationBuilder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SpeechToSpeechFileBuilder extends AbstractSpeechGenerationBuilder<SpeechToSpeechFileBuilder, File> {
|
||||
private File inputFile;
|
||||
|
||||
public File getInputFile() {
|
||||
return inputFile;
|
||||
}
|
||||
|
||||
public SpeechToSpeechFileBuilder setInputFile(File inputFile) {
|
||||
this.inputFile = inputFile;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpeechToSpeechFileBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File build() {
|
||||
return ElevenLabs
|
||||
.getSpeechToSpeechAPI()
|
||||
.generateSpeechToSpeech(getVoiceId(), getVoiceSettings(),getModelId(),getInputFile(),getLatencyOptimization());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.andrewcpu.elevenlabs.builders.impl.s2s;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.builders.abstracts.AbstractSpeechGenerationBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SpeechToSpeechStreamedBuilder extends AbstractSpeechGenerationBuilder<SpeechToSpeechStreamedBuilder, InputStream> {
|
||||
private File inputFile;
|
||||
|
||||
public File getInputFile() {
|
||||
return inputFile;
|
||||
}
|
||||
|
||||
public SpeechToSpeechStreamedBuilder setInputFile(File inputFile) {
|
||||
this.inputFile = inputFile;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpeechToSpeechStreamedBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream build() {
|
||||
return ElevenLabs
|
||||
.getSpeechToSpeechAPI()
|
||||
.generateSpeechToSpeechStream(getVoiceId(), getVoiceSettings(),getModelId(),getInputFile(),getLatencyOptimization());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.andrewcpu.elevenlabs.builders.impl.tts;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.builders.abstracts.AbstractSpeechGenerationBuilder;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TextToSpeechFileBuilder extends AbstractSpeechGenerationBuilder<TextToSpeechFileBuilder, File> {
|
||||
private String text;
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public TextToSpeechFileBuilder setText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextToSpeechFileBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File build() {
|
||||
return ElevenLabs
|
||||
.getTextToSpeechAPI()
|
||||
.generateTextToSpeech(getVoiceId(), getText(),getModelId(), getGeneratedAudioOutputFormat(),getLatencyOptimization(), getVoiceSettings());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package net.andrewcpu.elevenlabs.builders.impl.tts;
|
||||
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.builders.abstracts.AbstractSpeechGenerationBuilder;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class TextToSpeechStreamedBuilder extends AbstractSpeechGenerationBuilder<TextToSpeechStreamedBuilder, InputStream> {
|
||||
private String text;
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public TextToSpeechStreamedBuilder setText(String text) {
|
||||
this.text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextToSpeechStreamedBuilder self() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream build() {
|
||||
return ElevenLabs
|
||||
.getTextToSpeechAPI()
|
||||
.generateTextToSpeechStreamed(getVoiceId(), getText(),getModelId(), getGeneratedAudioOutputFormat(),getLatencyOptimization(), getVoiceSettings());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package net.andrewcpu.elevenlabs.enums;
|
||||
|
||||
public enum ElevenLabsVoiceModel {
|
||||
ELEVEN_MULTILINGUAL_V2("eleven_multilingual_v2", "Eleven Multilingual v2"),
|
||||
ELEVEN_ENGLISH_V2("eleven_english_v2", "Eleven English v2"),
|
||||
ELEVEN_MULTILINGUAL_V1("eleven_multilingual_v1", "Eleven Multilingual v1"),
|
||||
ELEVEN_MONOLINGUAL_V1("eleven_monolingual_v1", "Eleven English v1"),
|
||||
ELEVEN_TURBO_V2("eleven_turbo_v2", "Eleven Turbo v2"),
|
||||
ELEVEN_ENGLISH_STS_V2("eleven_english_sts_v2", "Eleven English v2", true),
|
||||
;
|
||||
final String modelId;
|
||||
final String modelLabel;
|
||||
final boolean supportsSpeechToSpeech;
|
||||
|
||||
ElevenLabsVoiceModel(String modelId, String modelLabel, boolean supportsSpeechToSpeech) {
|
||||
this.modelId = modelId;
|
||||
this.modelLabel = modelLabel;
|
||||
this.supportsSpeechToSpeech = supportsSpeechToSpeech;
|
||||
}
|
||||
|
||||
ElevenLabsVoiceModel(String modelId, String modelLabel) {
|
||||
this(modelId, modelLabel, false);
|
||||
}
|
||||
|
||||
public String getModelId() {
|
||||
return modelId;
|
||||
}
|
||||
|
||||
public String getModelLabel() {
|
||||
return modelLabel;
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,25 @@ import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class History extends ElevenModel {
|
||||
|
||||
public static final int DEFAULT_HISTORY_PAGE_SIZE = 100;
|
||||
public static History get() {
|
||||
return ElevenLabs.getHistoryAPI().getHistory();
|
||||
}
|
||||
public static History get(String afterHistoryId) {
|
||||
return ElevenLabs.getHistoryAPI().getHistory(afterHistoryId);
|
||||
}
|
||||
public static History get(int pageSize, String afterHistoryId) {
|
||||
return ElevenLabs.getHistoryAPI().getHistory(pageSize, afterHistoryId);
|
||||
}
|
||||
|
||||
public static History get(int pageSize) {
|
||||
return ElevenLabs.getHistoryAPI().getHistory(pageSize, null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@JsonProperty("history")
|
||||
private List<HistoryItem> historyItems;
|
||||
@@ -64,6 +77,13 @@ public class History extends ElevenModel {
|
||||
return ElevenLabs.getHistoryAPI().getHistoryItemAudio(Arrays.stream(items).map(HistoryItem::getHistoryItemId).toArray(String[]::new));
|
||||
}
|
||||
|
||||
public Optional<History> next(int pageSize) {
|
||||
if(!hasMore) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(ElevenLabs.getHistoryAPI().getHistory(pageSize, lastHistoryItemId));
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import net.andrewcpu.elevenlabs.ElevenLabs;
|
||||
import net.andrewcpu.elevenlabs.model.ElevenModel;
|
||||
import net.andrewcpu.elevenlabs.util.ElevenNetworkUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
@@ -131,6 +132,10 @@ public class HistoryItem extends ElevenModel {
|
||||
return ElevenLabs.getHistoryAPI().getHistoryItemAudio(historyItemId);
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return ElevenNetworkUtil.getHistoryItemUrl(historyItemId);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -167,28 +167,28 @@ public class Voice extends ElevenModel {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId,text, model, outputFormat,StreamLatencyOptimization.getDefault(), settings);
|
||||
}
|
||||
public File generate(String text, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,StreamLatencyOptimization.getDefault(), settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), outputFormat,StreamLatencyOptimization.getDefault(), settings);
|
||||
}
|
||||
public File generate(String text, VoiceSettings settings, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(),streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(),streamLatencyOptimization, settings);
|
||||
}
|
||||
|
||||
public File generate(String text, VoiceSettings settings, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), outputFormat,streamLatencyOptimization, settings);
|
||||
}
|
||||
public File generate(String text, GeneratedAudioOutputFormat outputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", outputFormat,streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), outputFormat,streamLatencyOptimization, settings);
|
||||
}
|
||||
public File generate(String text, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||
}
|
||||
|
||||
public File generate(String text, VoiceSettings settings) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), settings);
|
||||
}
|
||||
|
||||
public File generate(String text) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeech(voiceId, text, ElevenLabs.getDefaultModel(), settings);
|
||||
}
|
||||
|
||||
|
||||
@@ -202,11 +202,11 @@ public class Voice extends ElevenModel {
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, VoiceSettings settings) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), settings);
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), settings);
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, String model, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
@@ -218,11 +218,11 @@ public class Voice extends ElevenModel {
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, VoiceSettings settings, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, GeneratedAudioOutputFormat generatedAudioOutputFormat, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), generatedAudioOutputFormat, streamLatencyOptimization, settings);
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, String model, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
@@ -234,11 +234,11 @@ public class Voice extends ElevenModel {
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, VoiceSettings settings, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||
}
|
||||
|
||||
public InputStream generateStream(String text, StreamLatencyOptimization streamLatencyOptimization) {
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, "eleven_monolingual_v1", GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||
return ElevenLabs.getTextToSpeechAPI().generateTextToSpeechStreamed(voiceId, text, ElevenLabs.getDefaultModel(), GeneratedAudioOutputFormat.getDefault(), streamLatencyOptimization, settings);
|
||||
}
|
||||
|
||||
public File speechToSpeech(File audioFile, StreamLatencyOptimization latencyOptimization, String modelId, VoiceSettings voiceSettings) {
|
||||
|
||||
@@ -6,4 +6,9 @@ public abstract class DeleteRequest<T> extends ElevenLabsRequest<T> {
|
||||
public DeleteRequest(String endpoint, Class<T> clazz) {
|
||||
super(HttpRequestType.DELETE, endpoint, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public abstract class ElevenLabsRequest<T> {
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
Map<String, String> params = getQueryParameters();
|
||||
if(params.isEmpty()) return endpoint;
|
||||
return endpoint + "?" + buildQueryParameters(getQueryParameters());
|
||||
}
|
||||
|
||||
@@ -35,6 +37,4 @@ public abstract class ElevenLabsRequest<T> {
|
||||
}
|
||||
|
||||
public abstract Object getPayload();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,4 +6,9 @@ public abstract class GetRequest<T> extends ElevenLabsRequest<T> {
|
||||
public GetRequest(String endpoint, Class<T> clazz) {
|
||||
super(HttpRequestType.GET, endpoint, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class PostMultipartRequest<T> extends PostRequest<T> {
|
||||
public PostMultipartRequest(String endpoint, Class<T> clazz) {
|
||||
super(endpoint, clazz);
|
||||
}
|
||||
|
||||
|
||||
public abstract Map<String, Object> getMultipartParts(Map<String, Object> map);
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return getMultipartParts(new HashMap<>());
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,9 @@ public abstract class PostRequest<T> extends ElevenLabsRequest<T> {
|
||||
public PostRequest(String endpoint, Class<T> clazz) {
|
||||
super(HttpRequestType.POST, endpoint, clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package net.andrewcpu.elevenlabs.requests.audionative;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.request.CreateAudioNativeProjectRequest;
|
||||
import net.andrewcpu.elevenlabs.model.response.CreateAudioEnabledProjectModelResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostCreateAudioNativeProjectRequest extends PostRequest<CreateAudioEnabledProjectModelResponse> {
|
||||
public class PostCreateAudioNativeProjectRequest extends PostMultipartRequest<CreateAudioEnabledProjectModelResponse> {
|
||||
private final CreateAudioNativeProjectRequest request;
|
||||
public PostCreateAudioNativeProjectRequest(CreateAudioNativeProjectRequest request) {
|
||||
super("v1/audio-native", CreateAudioEnabledProjectModelResponse.class);
|
||||
@@ -15,8 +16,7 @@ public class PostCreateAudioNativeProjectRequest extends PostRequest<CreateAudio
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> payload) {
|
||||
payload.put("name", request.getName());
|
||||
payload.put("image", request.getImage());
|
||||
payload.put("author", request.getAuthor());
|
||||
|
||||
@@ -6,9 +6,4 @@ public class DeleteHistoryItemRequest extends DeleteRequest<String> {
|
||||
public DeleteHistoryItemRequest(String historyItemId) {
|
||||
super("v1/history/" + historyItemId, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ public class GetHistoryItemAudioRequest extends GetRequest<File> {
|
||||
public GetHistoryItemAudioRequest(String historyItemId) {
|
||||
super("v1/history/" + historyItemId + "/audio", File.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetHistoryItemByIdRequest extends GetRequest<HistoryItem> {
|
||||
public GetHistoryItemByIdRequest(String historyId) {
|
||||
super("v1/history/" + historyId, HistoryItem.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,36 @@ package net.andrewcpu.elevenlabs.requests.history;
|
||||
import net.andrewcpu.elevenlabs.model.history.History;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.andrewcpu.elevenlabs.model.history.History.DEFAULT_HISTORY_PAGE_SIZE;
|
||||
|
||||
public class GetHistoryRequest extends GetRequest<History> {
|
||||
private final int pageSize;
|
||||
private final String startAfterHistoryId;
|
||||
|
||||
public GetHistoryRequest() {
|
||||
this(DEFAULT_HISTORY_PAGE_SIZE, null);
|
||||
}
|
||||
|
||||
public GetHistoryRequest(String startAfterHistoryId) {
|
||||
this(DEFAULT_HISTORY_PAGE_SIZE, startAfterHistoryId);
|
||||
}
|
||||
|
||||
public GetHistoryRequest(int pageSize, String startAfterHistoryId) {
|
||||
super("v1/history", History.class);
|
||||
this.pageSize = pageSize;
|
||||
this.startAfterHistoryId = startAfterHistoryId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
public Map<String, String> getQueryParameters() {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("page_size", String.valueOf(pageSize));
|
||||
if(startAfterHistoryId != null) {
|
||||
params.put("start_after_history_item_id", startAfterHistoryId);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetModelsRequest extends GetRequest<GenerationTypeModel[]> {
|
||||
public GetModelsRequest() {
|
||||
super("v1/models", GenerationTypeModel[].class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,7 @@ package net.andrewcpu.elevenlabs.requests.projects;
|
||||
import net.andrewcpu.elevenlabs.requests.DeleteRequest;
|
||||
|
||||
public class DeleteChapterByIdRequest extends DeleteRequest<String> {
|
||||
|
||||
public DeleteChapterByIdRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,4 @@ public class DeleteProjectByIdRequest extends DeleteRequest<String> {
|
||||
public DeleteProjectByIdRequest(String projectId) {
|
||||
super("v1/projects/" + projectId, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetChapterByIdRequest extends GetRequest<Chapter> {
|
||||
public GetChapterByIdRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId, Chapter.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetChapterSnapshotsRequest extends GetRequest<ChapterSnapshotsModel
|
||||
public GetChapterSnapshotsRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/snapshots", ChapterSnapshotsModelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetProjectByIdRequest extends GetRequest<Project> {
|
||||
public GetProjectByIdRequest(String projectId) {
|
||||
super("v1/projects/" + projectId, Project.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetProjectChaptersRequest extends GetRequest<ChaptersModelResponse>
|
||||
public GetProjectChaptersRequest(String projectId) {
|
||||
super("v1/projects/" + projectId + "/chapters", ChaptersModelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetProjectSnapshotsRequest extends GetRequest<ProjectSnapshotsModel
|
||||
public GetProjectSnapshotsRequest(String projectId) {
|
||||
super("v1/projects/" + projectId + "/snapshots", ProjectSnapshotsModelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetProjectsRequest extends GetRequest<ProjectsModelResponse> {
|
||||
public GetProjectsRequest() {
|
||||
super("v1/projects", ProjectsModelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package net.andrewcpu.elevenlabs.requests.projects;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.request.AddProjectRequest;
|
||||
import net.andrewcpu.elevenlabs.model.response.ProjectModelResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostAddProjectRequest extends PostRequest<ProjectModelResponse> {
|
||||
public class PostAddProjectRequest extends PostMultipartRequest<ProjectModelResponse> {
|
||||
private final AddProjectRequest request;
|
||||
public PostAddProjectRequest(AddProjectRequest request) {
|
||||
super("v1/projects/add", ProjectModelResponse.class);
|
||||
@@ -15,8 +16,7 @@ public class PostAddProjectRequest extends PostRequest<ProjectModelResponse> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> payload) {
|
||||
payload.put("name",request.getName());
|
||||
payload.put("from_url", request.getFromUrl());
|
||||
payload.put("from_document", request.getFromDocument());
|
||||
|
||||
@@ -6,9 +6,4 @@ public class PostConvertChapterRequest extends PostRequest<String> {
|
||||
public PostConvertChapterRequest(String projectId, String chapterId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/convert", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,4 @@ public class PostConvertProjectRequest extends PostRequest<String> {
|
||||
public PostConvertProjectRequest(String projectId) {
|
||||
super("v1/projects/" + projectId + "/convert", String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ public class PostStreamChapterSnapshotAudioRequest extends PostRequest<InputStre
|
||||
public PostStreamChapterSnapshotAudioRequest(String projectId, String chapterId, String chapterSnapshotId) {
|
||||
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/snapshots/" + chapterSnapshotId + "/stream", InputStream.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ public class PostStreamProjectSnapshotAudioRequest extends PostRequest<InputStre
|
||||
public PostStreamProjectSnapshotAudioRequest(String projectId, String snapshotId) {
|
||||
super("v1/projects/" + projectId + "/snapshots/" + snapshotId + "/stream", InputStream.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,4 @@ public class DeleteSampleRequest extends DeleteRequest<String> {
|
||||
public DeleteSampleRequest(String voiceId, String sampleId) {
|
||||
super("v1/voices/" + voiceId + "/samples/" + sampleId, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,4 @@ public class GetSampleRequest extends GetRequest<File> {
|
||||
public GetSampleRequest(String voiceId, String sampleId) {
|
||||
super("v1/voices/" + voiceId + "/samples/" + sampleId + "/audio", File.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.requests.sts;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
@@ -31,9 +33,15 @@ public class PostSpeechToSpeechRequest extends PostRequest<File> {
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
String voiceSettingsString;
|
||||
try {
|
||||
voiceSettingsString = new ObjectMapper().writeValueAsString(voiceSettings);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
body.put("audio", audio);
|
||||
body.put("model_id", modelId);
|
||||
body.put("voice_settings", voiceSettings);
|
||||
body.put("voice_settings", voiceSettingsString);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.andrewcpu.elevenlabs.requests.sts;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.andrewcpu.elevenlabs.enums.StreamLatencyOptimization;
|
||||
import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
@@ -32,9 +34,15 @@ public class PostSpeechToSpeechStreamedRequest extends PostRequest<InputStream>
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
String voiceSettingsString;
|
||||
try {
|
||||
voiceSettingsString = new ObjectMapper().writeValueAsString(voiceSettings);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
body.put("audio", audio);
|
||||
body.put("model_id", modelId);
|
||||
body.put("voice_settings", voiceSettings);
|
||||
body.put("voice_settings", voiceSettingsString);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class PostTextToSpeechRequest extends PostRequest<File> {
|
||||
public Map<String, String> getQueryParameters() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("optimize_streaming_latency", String.valueOf(streamLatencyOptimization.getValue()));
|
||||
map.put("output_format", outputFormat.name());
|
||||
map.put("output_format", outputFormat.name().toLowerCase());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PostTextToSpeechStreamedRequest extends PostRequest<InputStream> {
|
||||
public Map<String, String> getQueryParameters() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("optimize_streaming_latency", String.valueOf(streamLatencyOptimization.getValue()));
|
||||
map.put("output_format", outputFormat.name());
|
||||
map.put("output_format", outputFormat.name().toLowerCase());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,7 @@ import net.andrewcpu.elevenlabs.model.user.Subscription;
|
||||
import net.andrewcpu.elevenlabs.requests.GetRequest;
|
||||
|
||||
public class GetSubscriptionRequest extends GetRequest<Subscription> {
|
||||
|
||||
public GetSubscriptionRequest() {
|
||||
super("v1/user/subscription", Subscription.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetUserRequest extends GetRequest<User> {
|
||||
public GetUserRequest() {
|
||||
super("v1/user", User.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,4 @@ public class DeleteVoiceRequest extends DeleteRequest<String> {
|
||||
public DeleteVoiceRequest(String voiceId) {
|
||||
super("v1/voices/" + voiceId, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetDefaultVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
||||
public GetDefaultVoiceSettingsRequest() {
|
||||
super("v1/voices/settings/default", VoiceSettings.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ public class GetVoiceRequest extends GetRequest<Voice> {
|
||||
this(voiceId, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GetVoiceRequest(String voiceId, boolean withSettings) {
|
||||
super( "v1/voices/" + voiceId, Voice.class);
|
||||
this.withSettings = withSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("with_settings", withSettings);
|
||||
public Map<String, String> getQueryParameters() {
|
||||
Map<String, String> payload = new HashMap<>();
|
||||
payload.put("with_settings", String.valueOf(withSettings));
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetVoiceSettingsRequest extends GetRequest<VoiceSettings> {
|
||||
public GetVoiceSettingsRequest(String voiceId) {
|
||||
super("v1/voices/" + voiceId + "/settings", VoiceSettings.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,4 @@ public class GetVoicesRequest extends GetRequest<VoiceModelResponse> {
|
||||
public GetVoicesRequest() {
|
||||
super("v1/voices", VoiceModelResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.andrewcpu.elevenlabs.requests.voices;
|
||||
|
||||
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostAddVoiceRequest extends PostRequest<CreateVoiceResponse> {
|
||||
public class PostAddVoiceRequest extends PostMultipartRequest<CreateVoiceResponse> {
|
||||
private final String name;
|
||||
private final File[] samples;
|
||||
private final String description;
|
||||
@@ -37,8 +38,7 @@ public class PostAddVoiceRequest extends PostRequest<CreateVoiceResponse> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> map) {
|
||||
map.put("name", this.name);
|
||||
map.put("files", this.samples);
|
||||
map.put("description", this.description);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package net.andrewcpu.elevenlabs.requests.voices;
|
||||
|
||||
import net.andrewcpu.elevenlabs.requests.PostMultipartRequest;
|
||||
import net.andrewcpu.elevenlabs.requests.PostRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PostEditVoiceRequest extends PostRequest<String> {
|
||||
public class PostEditVoiceRequest extends PostMultipartRequest<String> {
|
||||
private final String name;
|
||||
private final File[] samples;
|
||||
private final String description;
|
||||
@@ -36,8 +37,7 @@ public class PostEditVoiceRequest extends PostRequest<String> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPayload() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
public Map<String, Object> getMultipartParts(Map<String, Object> map) {
|
||||
map.put("name", this.name);
|
||||
map.put("files", this.samples);
|
||||
map.put("description", this.description);
|
||||
|
||||
@@ -66,22 +66,10 @@ public class ElevenNetworkUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static List<NameValuePair> getParameters(Object payload) {
|
||||
List<NameValuePair> parameters = new ArrayList<>();
|
||||
if (payload instanceof Map<?, ?>) {
|
||||
Map<?, ?> payloadMap = (Map<?, ?>) payload;
|
||||
for (Map.Entry<?, ?> entry : payloadMap.entrySet()) {
|
||||
parameters.add(new BasicNameValuePair(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())));
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
private static HttpUriRequestBase handleNonBodyRequest(HttpRequestType requestType, Object payload, String path) {
|
||||
List<NameValuePair> parameters = getParameters(payload);
|
||||
private static HttpUriRequestBase handleNonBodyRequest(HttpRequestType requestType, String path) {
|
||||
HttpUriRequestBase request = getRequest(requestType, path);
|
||||
try {
|
||||
request.setUri(new URIBuilder(path).addParameters(parameters).build());
|
||||
request.setUri(new URIBuilder(path).build());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -141,7 +129,7 @@ public class ElevenNetworkUtil {
|
||||
public static HttpUriRequestBase getRequest(HttpRequestType method, String path, Object payload) throws JsonProcessingException {
|
||||
HttpUriRequestBase request;
|
||||
if (method == HttpRequestType.GET || method == HttpRequestType.DELETE) {
|
||||
request = handleNonBodyRequest(method, payload, path);
|
||||
request = handleNonBodyRequest(method, path);
|
||||
} else {
|
||||
request = handleBodyRequest(method, payload, path);
|
||||
}
|
||||
@@ -149,6 +137,10 @@ public class ElevenNetworkUtil {
|
||||
return request;
|
||||
}
|
||||
|
||||
public static String getHistoryItemUrl(String historyItemId) {
|
||||
return BASE_URL + "v1/history/" + historyItemId + "/audio";
|
||||
}
|
||||
|
||||
public static <T> T sendRequest(HttpRequestType method, String path, Object payload, Class<T> responseType) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
path = BASE_URL + path;
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
package net.andrewcpu.elevenlabs;
|
||||
|
||||
|
||||
import net.andrewcpu.elevenlabs.builders.SpeechGenerationBuilder;
|
||||
import net.andrewcpu.elevenlabs.builders.abstracts.AbstractSpeechGenerationBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ElevenLabsTest {
|
||||
public static final String ELEVEN_LABS_API_KEY = System.getenv("ELEVENLABS_API_KEY");
|
||||
public static final String TEST_VOICE = "ZjJOFdM86g4E9U6OhzUo";
|
||||
|
||||
@@ -8,7 +8,9 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static net.andrewcpu.elevenlabs.model.history.History.DEFAULT_HISTORY_PAGE_SIZE;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class HistoryTest extends ElevenLabsTest {
|
||||
@@ -44,5 +46,7 @@ public class HistoryTest extends ElevenLabsTest {
|
||||
output.delete();
|
||||
}));
|
||||
|
||||
Optional<History> nextHistory = history.next(DEFAULT_HISTORY_PAGE_SIZE);
|
||||
assertTrue(nextHistory.isPresent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class AvailableModelsTest extends ElevenLabsTest {
|
||||
GenerationTypeModel[] models = null;
|
||||
try{
|
||||
models = ElevenLabs.getModelsAPI().getAvailableModels();
|
||||
System.out.println(Arrays.stream(models).map(Object::toString).collect(Collectors.toList()));
|
||||
Arrays.stream(models).map(o -> o.getModelId() + "," + o.getName()).forEach(System.out::println);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Failed to get voice type models: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user