5 Commits
v47 ... v51

Author SHA1 Message Date
Andrew Stein
688b469f6b Implemented projects API requests / models / responses. 2023-11-15 15:32:15 -05:00
Andrew Stein
388d059af7 Updated requests / models with new voice parameters. Preparing for Projects integration 2023-11-15 14:34:49 -05:00
Andrew Stein
1f9c48eac6 Merge remote-tracking branch 'origin/main' 2023-09-03 13:55:48 -04:00
Andrew Stein
b3ea0e2a09 Updated POM.xml 2023-09-03 13:55:35 -04:00
Andrew Stein
75eb64a077 Update README.md 2023-09-03 13:55:18 -04:00
42 changed files with 1463 additions and 16 deletions

View File

@@ -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
View File

@@ -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/projectSnapshots</url>
</snapshotRepository>
</distributionManagement>
</profile>
</profiles>
<groupId>net.andrewcpu</groupId>
<artifactId>elevenlabs-api</artifactId>
<version>2.1-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>

View File

@@ -1,10 +1,14 @@
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.projects.Project;
import net.andrewcpu.elevenlabs.model.request.TextToSpeechRequest;
import net.andrewcpu.elevenlabs.model.response.CreateVoiceResponse;
import net.andrewcpu.elevenlabs.model.response.GenerationTypeModel;
import net.andrewcpu.elevenlabs.model.response.ProjectsModelResponse;
import net.andrewcpu.elevenlabs.model.user.Subscription;
import net.andrewcpu.elevenlabs.model.user.User;
import net.andrewcpu.elevenlabs.model.voice.Voice;
@@ -12,6 +16,7 @@ import net.andrewcpu.elevenlabs.model.voice.VoiceSettings;
import net.andrewcpu.elevenlabs.requests.ElevenLabsRequest;
import net.andrewcpu.elevenlabs.requests.history.*;
import net.andrewcpu.elevenlabs.requests.models.GetModelsRequest;
import net.andrewcpu.elevenlabs.requests.projects.GetProjectsRequest;
import net.andrewcpu.elevenlabs.requests.samples.DeleteSampleRequest;
import net.andrewcpu.elevenlabs.requests.samples.GetSampleRequest;
import net.andrewcpu.elevenlabs.requests.tts.PostTextToSpeechRequest;
@@ -97,6 +102,10 @@ public class ElevenLabs {
return sendRequest(new GetVoiceRequest(voiceId, withSettings));
}
public static ProjectsModelResponse getProjects() {
return sendRequest(new GetProjectsRequest());
}
public static String deleteVoice(String voiceId) {
return sendRequest(new DeleteVoiceRequest(voiceId));
}
@@ -120,6 +129,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)));
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,11 @@
package net.andrewcpu.elevenlabs.enums;
public enum ProjectOutputQuality {
STANDARD,
HIGH,
ULTRA;
public static ProjectOutputQuality getDefault() {
return STANDARD;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,27 @@
package net.andrewcpu.elevenlabs.model.projects;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
public class Chapter extends ElevenModel {
@JsonProperty("chapter_id")
private String chapterId;
@JsonProperty("name")
private String name;
@JsonProperty("last_conversion_date_unix")
private long lastConversionDateUnix;
@JsonProperty("conversion_progress")
private double conversionProgress;
@JsonProperty("can_be_downloaded")
private boolean canBeDownloaded;
@JsonProperty("state")
private String state;
@JsonProperty("statistics")
private Statistics statistics;
}

View File

@@ -0,0 +1,69 @@
package net.andrewcpu.elevenlabs.model.projects;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
public class ChapterSnapshot extends ElevenModel {
public ChapterSnapshot() {
}
public ChapterSnapshot(String chapterSnapshotId, String projectId, String chapterId, long createdAtUnix, String name) {
this.chapterSnapshotId = chapterSnapshotId;
this.projectId = projectId;
this.chapterId = chapterId;
this.createdAtUnix = createdAtUnix;
this.name = name;
}
@JsonProperty("chapter_snapshot_id")
private String chapterSnapshotId;
@JsonProperty("project_id")
private String projectId;
@JsonProperty("chapter_id")
private String chapterId;
@JsonProperty("created_at_unix")
private long createdAtUnix;
@JsonProperty("name")
private String name;
@JsonIgnore
public String getChapterSnapshotId() {
return chapterSnapshotId;
}
@JsonIgnore
public String getChapterId() {
return chapterId;
}
@JsonIgnore
public String getProjectId() {
return projectId;
}
@JsonIgnore
public long getCreatedAtUnix() {
return createdAtUnix;
}
@JsonIgnore
public String getName() {
return name;
}
@Override
@JsonIgnore
public String toString() {
return "ChapterSnapshot{" +
"chapterSnapshotId='" + chapterSnapshotId + '\'' +
", projectId='" + projectId + '\'' +
", chapterId='" + chapterId + '\'' +
", createdAtUnix=" + createdAtUnix +
", name='" + name + '\'' +
'}';
}
}

View File

@@ -0,0 +1,113 @@
package net.andrewcpu.elevenlabs.model.projects;
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.util.List;
public class Project extends ElevenModel {
public static List<Project> getProjects() {
return ElevenLabs.getProjects().getProjects();
}
@JsonProperty("project_id")
private String projectId;
@JsonProperty("name")
private String name;
@JsonProperty("create_date_unix")
private long unixCreateDate;
@JsonProperty("default_title_voice_id")
private String defaultTitleVoiceId;
@JsonProperty("default_paragraph_voice_id")
private String defaultParagraphVoiceId;
@JsonProperty("default_model_id")
private String defaultModelId;
@JsonProperty("last_conversion_date_unix")
private long lastConversionDateUnix;
@JsonProperty("can_be_downloaded")
private boolean canBeDownloaded;
@JsonProperty("state")
private String state;
@JsonProperty("chapters")
private List<Chapter> chapters;
@JsonIgnore
public String getProjectId() {
return projectId;
}
@JsonIgnore
public String getName() {
return name;
}
@JsonIgnore
public long getUnixCreateDate() {
return unixCreateDate;
}
@JsonIgnore
public String getDefaultTitleVoiceId() {
return defaultTitleVoiceId;
}
@JsonIgnore
public String getDefaultParagraphVoiceId() {
return defaultParagraphVoiceId;
}
@JsonIgnore
public String getDefaultModelId() {
return defaultModelId;
}
@JsonIgnore
public long getLastConversionDateUnix() {
return lastConversionDateUnix;
}
@JsonIgnore
public boolean isCanBeDownloaded() {
return canBeDownloaded;
}
@JsonIgnore
public String getState() {
return state;
}
@JsonIgnore
public List<Chapter> getChapters() {
return chapters;
}
@Override
@JsonIgnore
public String toString() {
return "Project{" +
"projectId='" + projectId + '\'' +
", name='" + name + '\'' +
", unixCreateDate=" + unixCreateDate +
", defaultTitleVoiceId='" + defaultTitleVoiceId + '\'' +
", defaultParagraphVoiceId='" + defaultParagraphVoiceId + '\'' +
", defaultModelId='" + defaultModelId + '\'' +
", lastConversionDateUnix=" + lastConversionDateUnix +
", canBeDownloaded=" + canBeDownloaded +
", state='" + state + '\'' +
", chapters=" + chapters +
'}';
}
}

View File

@@ -0,0 +1,60 @@
package net.andrewcpu.elevenlabs.model.projects;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
public class ProjectSnapshot extends ElevenModel {
public ProjectSnapshot() {
}
public ProjectSnapshot(String projectSnapshotId, String projectId, long createdAtUnix, String name) {
this.projectSnapshotId = projectSnapshotId;
this.projectId = projectId;
this.createdAtUnix = createdAtUnix;
this.name = name;
}
@JsonProperty("project_snapshot_id")
private String projectSnapshotId;
@JsonProperty("project_id")
private String projectId;
@JsonProperty("created_at_unix")
private long createdAtUnix;
@JsonProperty("name")
private String name;
@JsonIgnore
public String getProjectSnapshotId() {
return projectSnapshotId;
}
@JsonIgnore
public String getProjectId() {
return projectId;
}
@JsonIgnore
public long getCreatedAtUnix() {
return createdAtUnix;
}
@JsonIgnore
public String getName() {
return name;
}
@Override
@JsonIgnore
public String toString() {
return "Snapshot{" +
"projectSnapshotId='" + projectSnapshotId + '\'' +
", projectId='" + projectId + '\'' +
", createdAtUnix=" + createdAtUnix +
", name='" + name + '\'' +
'}';
}
}

View File

@@ -0,0 +1,62 @@
package net.andrewcpu.elevenlabs.model.projects;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
public class Statistics extends ElevenModel {
@JsonProperty("characters_unconverted")
private int charactersUnconverted;
@JsonProperty("characters_converted")
private int charactersConverted;
@JsonProperty("paragraphs_converted")
private int paragraphsConverted;
@JsonProperty("paragraphs_unconverted")
private int paragraphsUnconverted;
public Statistics(int charactersUnconverted, int charactersConverted, int paragraphsConverted, int paragraphsUnconverted) {
this.charactersUnconverted = charactersUnconverted;
this.charactersConverted = charactersConverted;
this.paragraphsConverted = paragraphsConverted;
this.paragraphsUnconverted = paragraphsUnconverted;
}
public Statistics() {
}
@JsonIgnore
public int getCharactersUnconverted() {
return charactersUnconverted;
}
@JsonIgnore
public int getCharactersConverted() {
return charactersConverted;
}
@JsonIgnore
public int getParagraphsConverted() {
return paragraphsConverted;
}
@JsonIgnore
public int getParagraphsUnconverted() {
return paragraphsUnconverted;
}
@Override
@JsonIgnore
public String toString() {
return "Statistics{" +
"charactersUnconverted=" + charactersUnconverted +
", charactersConverted=" + charactersConverted +
", paragraphsConverted=" + paragraphsConverted +
", paragraphsUnconverted=" + paragraphsUnconverted +
'}';
}
}

View File

@@ -0,0 +1,119 @@
package net.andrewcpu.elevenlabs.model.request;
import net.andrewcpu.elevenlabs.enums.ProjectOutputQuality;
import java.io.File;
import java.lang.invoke.StringConcatFactory;
public class AddProjectRequest {
private String name;
private String fromUrl;
private File fromDocument;
private String defaultTitleVoiceId;
private String defaultParagraphVoiceId;
private String defaultModelId;
private ProjectOutputQuality projectOutputQuality;
private String title;
private String author;
private String isbnNumber;
private boolean acxVolumeNormalization;
public String getName() {
return name;
}
public AddProjectRequest setName(String name) {
this.name = name;
return this;
}
public String getFromUrl() {
return fromUrl;
}
public AddProjectRequest setFromUrl(String fromUrl) {
this.fromUrl = fromUrl;
return this;
}
public File getFromDocument() {
return fromDocument;
}
public AddProjectRequest setFromDocument(File fromDocument) {
this.fromDocument = fromDocument;
return this;
}
public String getDefaultTitleVoiceId() {
return defaultTitleVoiceId;
}
public AddProjectRequest setDefaultTitleVoiceId(String defaultTitleVoiceId) {
this.defaultTitleVoiceId = defaultTitleVoiceId;
return this;
}
public String getDefaultParagraphVoiceId() {
return defaultParagraphVoiceId;
}
public AddProjectRequest setDefaultParagraphVoiceId(String defaultParagraphVoiceId) {
this.defaultParagraphVoiceId = defaultParagraphVoiceId;
return this;
}
public String getDefaultModelId() {
return defaultModelId;
}
public AddProjectRequest setDefaultModelId(String defaultModelId) {
this.defaultModelId = defaultModelId;
return this;
}
public ProjectOutputQuality getProjectOutputQuality() {
return projectOutputQuality;
}
public AddProjectRequest setProjectOutputQuality(ProjectOutputQuality projectOutputQuality) {
this.projectOutputQuality = projectOutputQuality;
return this;
}
public String getTitle() {
return title;
}
public AddProjectRequest setTitle(String title) {
this.title = title;
return this;
}
public String getAuthor() {
return author;
}
public AddProjectRequest setAuthor(String author) {
this.author = author;
return this;
}
public String getIsbnNumber() {
return isbnNumber;
}
public AddProjectRequest setIsbnNumber(String isbnNumber) {
this.isbnNumber = isbnNumber;
return this;
}
public boolean isAcxVolumeNormalization() {
return acxVolumeNormalization;
}
public AddProjectRequest setAcxVolumeNormalization(boolean acxVolumeNormalization) {
this.acxVolumeNormalization = acxVolumeNormalization;
return this;
}
}

View File

@@ -0,0 +1,119 @@
package net.andrewcpu.elevenlabs.model.request;
import net.andrewcpu.elevenlabs.model.ElevenModel;
import javax.management.loading.PrivateClassLoader;
import java.io.File;
public class CreateAudioNativeProjectRequest extends ElevenModel {
private String name;
private String image;
private String author;
private boolean small;
private String textColor;
private String backgroundColor;
private Integer sessionization;
private String voiceId;
private String modelId;
private File file;
private boolean autoConvert;
public String getName() {
return name;
}
public CreateAudioNativeProjectRequest setName(String name) {
this.name = name;
return this;
}
public String getImage() {
return image;
}
public CreateAudioNativeProjectRequest setImage(String image) {
this.image = image;
return this;
}
public String getAuthor() {
return author;
}
public CreateAudioNativeProjectRequest setAuthor(String author) {
this.author = author;
return this;
}
public boolean isSmall() {
return small;
}
public CreateAudioNativeProjectRequest setSmall(boolean small) {
this.small = small;
return this;
}
public String getTextColor() {
return textColor;
}
public CreateAudioNativeProjectRequest setTextColor(String textColor) {
this.textColor = textColor;
return this;
}
public String getBackgroundColor() {
return backgroundColor;
}
public CreateAudioNativeProjectRequest setBackgroundColor(String backgroundColor) {
this.backgroundColor = backgroundColor;
return this;
}
public Integer getSessionization() {
return sessionization;
}
public CreateAudioNativeProjectRequest setSessionization(Integer sessionization) {
this.sessionization = sessionization;
return this;
}
public String getVoiceId() {
return voiceId;
}
public CreateAudioNativeProjectRequest setVoiceId(String voiceId) {
this.voiceId = voiceId;
return this;
}
public String getModelId() {
return modelId;
}
public CreateAudioNativeProjectRequest setModelId(String modelId) {
this.modelId = modelId;
return this;
}
public File getFile() {
return file;
}
public CreateAudioNativeProjectRequest setFile(File file) {
this.file = file;
return this;
}
public boolean isAutoConvert() {
return autoConvert;
}
public CreateAudioNativeProjectRequest setAutoConvert(boolean autoConvert) {
this.autoConvert = autoConvert;
return this;
}
}

View File

@@ -0,0 +1,35 @@
package net.andrewcpu.elevenlabs.model.response;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
import net.andrewcpu.elevenlabs.model.projects.ChapterSnapshot;
import java.util.List;
public class ChapterSnapshotsModelResponse extends ElevenModel {
public ChapterSnapshotsModelResponse(List<ChapterSnapshot> snapshots) {
this.snapshots = snapshots;
}
public ChapterSnapshotsModelResponse() {
}
@JsonProperty("snapshots")
private List<ChapterSnapshot> snapshots;
@JsonIgnore
public List<ChapterSnapshot> getSnapshots() {
return snapshots;
}
@Override
@JsonIgnore
public String toString() {
return "ChapterSnapshotsModelResponse{" +
"snapshots=" + snapshots +
'}';
}
}

View File

@@ -0,0 +1,33 @@
package net.andrewcpu.elevenlabs.model.response;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
import net.andrewcpu.elevenlabs.model.projects.Chapter;
import java.util.List;
public class ChaptersModelResponse extends ElevenModel {
@JsonProperty("chapters")
private List<Chapter> chapters;
public ChaptersModelResponse(List<Chapter> chapters) {
this.chapters = chapters;
}
public ChaptersModelResponse() {
}
@JsonIgnore
public List<Chapter> getChapters() {
return chapters;
}
@Override
@JsonIgnore
public String toString() {
return "ChaptersModelResponse{" +
"chapters=" + chapters +
'}';
}
}

View File

@@ -0,0 +1,50 @@
package net.andrewcpu.elevenlabs.model.response;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
public class CreateAudioEnabledProjectModelResponse extends ElevenModel {
@JsonProperty("project_id")
private String projectId;
@JsonProperty("converting")
private boolean converting;
@JsonProperty("html_snippet")
private String htmlSnippet;
public CreateAudioEnabledProjectModelResponse(String projectId, boolean converting, String htmlSnippet) {
this.projectId = projectId;
this.converting = converting;
this.htmlSnippet = htmlSnippet;
}
public CreateAudioEnabledProjectModelResponse() {
}
@JsonIgnore
public String getProjectId() {
return projectId;
}
@JsonIgnore
public boolean isConverting() {
return converting;
}
@JsonIgnore
public String getHtmlSnippet() {
return htmlSnippet;
}
@Override
@JsonIgnore
public String toString() {
return "CreateAudioEnabledProjectModelResponse{" +
"projectId='" + projectId + '\'' +
", converting=" + converting +
", htmlSnippet='" + htmlSnippet + '\'' +
'}';
}
}

View File

@@ -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 +
'}';
}

View File

@@ -0,0 +1,31 @@
package net.andrewcpu.elevenlabs.model.response;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
import net.andrewcpu.elevenlabs.model.projects.Project;
public class ProjectModelResponse extends ElevenModel {
@JsonProperty("project")
private Project project;
public ProjectModelResponse(Project project) {
this.project = project;
}
public ProjectModelResponse() {
}
@JsonIgnore
public Project getProject() {
return project;
}
@Override
@JsonIgnore
public String toString() {
return "ProjectModelResponse{" +
"project=" + project +
'}';
}
}

View File

@@ -0,0 +1,34 @@
package net.andrewcpu.elevenlabs.model.response;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
import net.andrewcpu.elevenlabs.model.projects.ProjectSnapshot;
import java.util.List;
public class ProjectSnapshotsModelResponse extends ElevenModel {
@JsonProperty("snapshots")
private List<ProjectSnapshot> projectSnapshots;
public ProjectSnapshotsModelResponse(List<ProjectSnapshot> projectSnapshots) {
this.projectSnapshots = projectSnapshots;
}
public ProjectSnapshotsModelResponse() {
}
@JsonIgnore
public List<ProjectSnapshot> getSnapshots() {
return projectSnapshots;
}
@Override
@JsonIgnore
public String toString() {
return "ProjectSnapshotsModelResponse{" +
"snapshots=" + projectSnapshots +
'}';
}
}

View File

@@ -0,0 +1,33 @@
package net.andrewcpu.elevenlabs.model.response;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import net.andrewcpu.elevenlabs.model.ElevenModel;
import net.andrewcpu.elevenlabs.model.projects.Project;
import java.util.List;
public class ProjectsModelResponse extends ElevenModel {
@JsonProperty("projects")
private List<Project> projects;
public ProjectsModelResponse(List<Project> projects) {
this.projects = projects;
}
public ProjectsModelResponse() {
}
@JsonIgnore
public List<Project> getProjects() {
return projects;
}
@Override
@JsonIgnore
public String toString() {
return "ProjectsModelResponse{" +
"projects=" + projects +
'}';
}
}

View File

@@ -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 +
'}';
}
}

View File

@@ -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 +
'}';
}
}

View File

@@ -2,6 +2,11 @@ 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;
@@ -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() {

View File

@@ -0,0 +1,33 @@
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.PostRequest;
import java.util.HashMap;
import java.util.Map;
public class PostCreateAudioNativeProjectRequest extends PostRequest<CreateAudioEnabledProjectModelResponse> {
private CreateAudioNativeProjectRequest request;
public PostCreateAudioNativeProjectRequest(CreateAudioNativeProjectRequest request) {
super("v1/audio-native", CreateAudioEnabledProjectModelResponse.class);
this.request = request;
}
@Override
public Object getPayload() {
Map<String, Object> payload = new HashMap<>();
payload.put("name", request.getName());
payload.put("image", request.getImage());
payload.put("author", request.getAuthor());
payload.put("small", request.isSmall());
payload.put("text_color", request.getTextColor());
payload.put("background_color", request.getBackgroundColor());
payload.put("sessionization", request.getSessionization());
payload.put("voice_id", request.getVoiceId());
payload.put("model_id", request.getModelId());
payload.put("file", request.getFile());
payload.put("auto_convert", request.isAutoConvert());
return payload;
}
}

View File

@@ -0,0 +1,15 @@
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;
}
}

View File

@@ -0,0 +1,14 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.requests.DeleteRequest;
public class DeleteProjectByIdRequest extends DeleteRequest<String> {
public DeleteProjectByIdRequest(String projectId) {
super("v1/projects/" + projectId, String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,15 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.model.projects.Chapter;
import net.andrewcpu.elevenlabs.requests.GetRequest;
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;
}
}

View File

@@ -0,0 +1,14 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.requests.GetRequest;
public class GetChapterSnapshotsRequest extends GetRequest<GetChapterSnapshotsRequest> {
public GetChapterSnapshotsRequest(String projectId, String chapterId) {
super("v1/projects/" + projectId + "/chapters/" + chapterId + "/snapshots", GetChapterSnapshotsRequest.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,15 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.model.projects.Project;
import net.andrewcpu.elevenlabs.requests.GetRequest;
public class GetProjectByIdRequest extends GetRequest<Project> {
public GetProjectByIdRequest(String projectId) {
super("v1/projects/" + projectId, Project.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,15 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.model.response.ChaptersModelResponse;
import net.andrewcpu.elevenlabs.requests.GetRequest;
public class GetProjectChaptersRequest extends GetRequest<ChaptersModelResponse> {
public GetProjectChaptersRequest(String projectId) {
super("v1/projects/" + projectId + "/chapters", ChaptersModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,15 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.model.response.ProjectSnapshotsModelResponse;
import net.andrewcpu.elevenlabs.requests.GetRequest;
public class GetProjectSnapshotsRequest extends GetRequest<ProjectSnapshotsModelResponse> {
public GetProjectSnapshotsRequest(String projectId) {
super("v1/projects/" + projectId + "/snapshots", ProjectSnapshotsModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,17 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.model.response.ProjectsModelResponse;
import net.andrewcpu.elevenlabs.requests.GetRequest;
import java.util.HashMap;
public class GetProjectsRequest extends GetRequest<ProjectsModelResponse> {
public GetProjectsRequest() {
super("v1/projects", ProjectsModelResponse.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,33 @@
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.PostRequest;
import java.util.HashMap;
import java.util.Map;
public class PostAddProjectRequest extends PostRequest<ProjectModelResponse> {
private AddProjectRequest request;
public PostAddProjectRequest(AddProjectRequest request) {
super("v1/projects/add", ProjectModelResponse.class);
this.request = request;
}
@Override
public Object getPayload() {
Map<String, Object> payload = new HashMap<>();
payload.put("name",request.getName());
payload.put("from_url", request.getFromUrl());
payload.put("from_document", request.getFromDocument());
payload.put("default_title_voice_id", request.getDefaultTitleVoiceId());
payload.put("default_paragraph_voice_id", request.getDefaultParagraphVoiceId());
payload.put("default_model_id", request.getDefaultModelId());
payload.put("quality_preset", request.getProjectOutputQuality().name().toLowerCase());
payload.put("title", request.getTitle());
payload.put("author", request.getAuthor());
payload.put("isbn_number", request.getIsbnNumber());
payload.put("acx_volume_normalization", request.isAcxVolumeNormalization());
return payload;
}
}

View File

@@ -0,0 +1,14 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.requests.PostRequest;
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;
}
}

View File

@@ -0,0 +1,14 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.requests.PostRequest;
public class PostConvertProjectRequest extends PostRequest<String> {
public PostConvertProjectRequest(String projectId) {
super("v1/projects/" + projectId + "/convert", String.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -0,0 +1,16 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.requests.PostRequest;
import java.io.InputStream;
public class PostStreamChapterSnapshotAudioRequest extends PostRequest<InputStream> {
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;
}
}

View File

@@ -0,0 +1,16 @@
package net.andrewcpu.elevenlabs.requests.projects;
import net.andrewcpu.elevenlabs.requests.PostRequest;
import java.io.InputStream;
public class PostStreamProjectSnapshotAudioRequest extends PostRequest<InputStream> {
public PostStreamProjectSnapshotAudioRequest(String projectId, String snapshotId) {
super("v1/projects/" + projectId + "/snapshots/" + snapshotId + "/stream", InputStream.class);
}
@Override
public Object getPayload() {
return null;
}
}

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -21,9 +21,11 @@ import org.apache.hc.core5.net.URIBuilder;
import java.io.*;
import java.net.URISyntaxException;
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/";
@@ -34,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) {
@@ -137,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);

View File

@@ -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);

View File

@@ -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");