mirror of
https://github.com/Andrewcpu/elevenlabs-api.git
synced 2026-05-06 03:00:23 -04:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
388d059af7 | ||
|
|
1f9c48eac6 | ||
|
|
b3ea0e2a09 | ||
|
|
75eb64a077 | ||
|
|
c5706317aa | ||
|
|
0a2f6d1869 | ||
|
|
b753769a53 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: Dev Build
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
@@ -14,9 +14,9 @@ I downgraded the repo from JDK 17 to JDK 11 as well.
|
||||
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>2.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/)
|
||||
|
||||
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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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 +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ 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;
|
||||
|
||||
@@ -58,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;
|
||||
@@ -143,6 +148,7 @@ public class Voice extends ElevenModel {
|
||||
this.sharing = refreshedData.sharing;
|
||||
this.previewUrl = refreshedData.previewUrl;
|
||||
this.category = refreshedData.category;
|
||||
this.highQualityBaseModelIds = refreshedData.highQualityBaseModelIds;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -154,6 +160,29 @@ public class Voice extends ElevenModel {
|
||||
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);
|
||||
}
|
||||
@@ -162,6 +191,8 @@ public class Voice extends ElevenModel {
|
||||
return ElevenLabs.generateTextToSpeech(voiceId, text, "eleven_monolingual_v1", settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public InputStream generateStream(String text, String model) {
|
||||
return ElevenLabs.generateTextToSpeechStreamed(voiceId, text, model, settings);
|
||||
}
|
||||
@@ -179,8 +210,44 @@ public class Voice extends ElevenModel {
|
||||
}
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
|
||||
|
||||
|
||||
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 + '\'' +
|
||||
@@ -194,6 +261,7 @@ public class Voice extends ElevenModel {
|
||||
", availableForTiers=" + availableForTiers +
|
||||
", settings=" + settings +
|
||||
", sharing=" + sharing +
|
||||
", highQualityBaseModelIds=" + highQualityBaseModelIds +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,24 @@ public class VoiceSettings extends ElevenModel {
|
||||
@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() {
|
||||
@@ -34,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,6 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
||||
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||
|
||||
public abstract class DeleteRequest<T> extends ElevenLabsRequest<T> {
|
||||
public DeleteRequest(String endpoint, Class<T> clazz) {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
||||
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;
|
||||
@@ -18,7 +23,11 @@ public abstract class ElevenLabsRequest<T> {
|
||||
}
|
||||
|
||||
public String getEndpoint() {
|
||||
return endpoint;
|
||||
return endpoint + "?" + buildQueryParameters(getQueryParameters());
|
||||
}
|
||||
|
||||
public Map<String, String> getQueryParameters() {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
public Class<T> getResponseClass() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
||||
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||
|
||||
public abstract class GetRequest<T> extends ElevenLabsRequest<T> {
|
||||
public GetRequest(String endpoint, Class<T> clazz) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
||||
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||
|
||||
public abstract class PostRequest<T> extends ElevenLabsRequest<T> {
|
||||
public PostRequest(String endpoint, Class<T> clazz) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.andrewcpu.elevenlabs.requests;
|
||||
|
||||
import net.andrewcpu.elevenlabs.HttpRequestType;
|
||||
import net.andrewcpu.elevenlabs.enums.HttpRequestType;
|
||||
|
||||
public abstract class PutRequest<T> extends ElevenLabsRequest<T> {
|
||||
public PutRequest(String endpoint, Class<T> clazz) {
|
||||
|
||||
@@ -1,19 +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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,54 @@
|
||||
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
|
||||
|
||||
@@ -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