Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<p align="center">

<a href="https://central.sonatype.com/artifact/io.github.barqawiz/intellijava.core/0.8.0" alt="maven build">
<a href="https://central.sonatype.com/artifact/io.github.barqawiz/intellijava.core/0.8.2" alt="maven build">
<img src="https://img.shields.io/maven-central/v/io.github.barqawiz/intellijava.core?style=flat-square" />
</a>

Expand Down Expand Up @@ -40,23 +40,23 @@ Maven:
<dependency>
<groupId>io.github.barqawiz</groupId>
<artifactId>intellijava.core</artifactId>
<version>0.8.0</version>
<version>0.8.2</version>
</dependency>
```

Gradle:

```
implementation 'io.github.barqawiz:intellijava.core:0.8.0'
implementation 'io.github.barqawiz:intellijava.core:0.8.2'
```

Gradle(Kotlin):
```
implementation("io.github.barqawiz:intellijava.core:0.8.0")
implementation("io.github.barqawiz:intellijava.core:0.8.2")
```

Jar download:
[intellijava.jar](https://repo1.maven.org/maven2/io/github/barqawiz/intellijava.core/0.8.0/intellijava.core-0.8.0.jar).
[intellijava.jar](https://repo1.maven.org/maven2/io/github/barqawiz/intellijava.core/0.8.2/intellijava.core-0.8.2.jar).

## Code Example
**Language model code** (2 steps):
Expand Down
2 changes: 1 addition & 1 deletion core/com.intellijava.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.barqawiz</groupId>
<artifactId>intellijava.core</artifactId>
<version>0.8.0</version>
<version>0.8.2</version>

<name>Intellijava</name>
<description>IntelliJava allows java developers to easily integrate with the latest language models, image generation, and deep learning frameworks.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public List<String> getSupportedModels() {
}

/**
* Generates speech from text using the support models.
* Generates speech using advanced audio models.
*
* You can save the returned byte to audio file using FileOutputStream("path/audio.mp3").
* You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
*
* @param input SpeechInput object containing the text and gender to use.
* @return byte array of the decoded audio content.
Expand All @@ -121,7 +121,101 @@ public List<String> getSupportedModels() {
public byte[] generateEnglishText(Text2SpeechInput input) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), "en-gb");
return this.generateGoogleText(input.getText(), input.getGender(), "en-GB");
} else {
throw new IllegalArgumentException("the keyType not supported");
}
}


/**
* Generates speech using advanced audio models.
*
* You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
*
* @param input SpeechInput object containing the text and gender to use.
* @return byte array of the decoded audio content.
* @throws IOException in case of communication error.
*/
public byte[] generateMandarinText(Text2SpeechInput input) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), "cmn-CN");
} else {
throw new IllegalArgumentException("the keyType not supported");
}
}

/**
* Generates speech using advanced audio models.
*
* You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
*
* @param input SpeechInput object containing the text and gender to use.
* @return byte array of the decoded audio content.
* @throws IOException in case of communication error.
*/
public byte[] generateArabicText(Text2SpeechInput input) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), "ar-XA");
} else {
throw new IllegalArgumentException("the keyType not supported");
}
}


/**
* Generates speech using advanced audio models.
*
* You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
*
* @param input SpeechInput object containing the text and gender to use.
* @return byte array of the decoded audio content.
* @throws IOException in case of communication error.
*/
public byte[] generateTurkishText(Text2SpeechInput input) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), "tr-TR");
} else {
throw new IllegalArgumentException("the keyType not supported");
}
}

/**
* Generates speech using advanced audio models.
*
* You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
*
* @param input SpeechInput object containing the text and gender to use.
* @param langCode the language code, make sure to use the right code for the model engine.
* @return byte array of the decoded audio content.
* @throws IOException in case of communication error.
*/
public byte[] generateText(Text2SpeechInput input, String langCode) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), langCode);
} else {
throw new IllegalArgumentException("the keyType not supported");
}
}


/**
* Generates speech using advanced audio models.
*
* You can save the result byte to audio file using FileOutputStream("path/audio.mp3").
*
* @param input SpeechInput object containing the text and gender to use.
* @return byte array of the decoded audio content.
* @throws IOException in case of communication error.
*/
public byte[] generateGermanText(Text2SpeechInput input) throws IOException {

if (this.keyType == SpeechModels.google) {
return this.generateGoogleText(input.getText(), input.getGender(), "de-de");
} else {
throw new IllegalArgumentException("the keyType not supported");
}
Expand All @@ -143,13 +237,56 @@ private byte[] generateGoogleText(String text, Gender gender, String language) t
params.put("text", text);
params.put("languageCode", language);

if (gender == Gender.FEMALE) {
params.put("name", "en-GB-Standard-A");
params.put("ssmlGender", "FEMALE");
} else {
params.put("name", "en-GB-Standard-B");
params.put("ssmlGender", "MALE");
}
language = language.toLowerCase();

if (language.equals("en-gb")) {
// English
if (gender == Gender.FEMALE) {
params.put("name", "en-GB-Standard-A");
params.put("ssmlGender", "FEMALE");
} else {
params.put("name", "en-GB-Standard-B");
params.put("ssmlGender", "MALE");
}
} else if (language.equals("tr-tr")) {
// Turkish
if (gender == Gender.FEMALE) {
params.put("name", "tr-TR-Standard-A");
params.put("ssmlGender", "FEMALE");
} else {
params.put("name", "tr-TR-Standard-B");
params.put("ssmlGender", "MALE");
}
} else if (language.equals("cmn-cn")) {
// Mandarin Chinese
if (gender == Gender.FEMALE) {
params.put("name", "cmn-CN-Standard-A");
params.put("ssmlGender", "FEMALE");
} else {
params.put("name", "cmn-CN-Standard-B");
params.put("ssmlGender", "MALE");
}
} else if (language.equals("de-de")) {
// German (Germany)
if (gender == Gender.FEMALE) {
params.put("name", "de-DE-Standard-A");
params.put("ssmlGender", "FEMALE");
} else {
params.put("name", "de-DE-Standard-B");
params.put("ssmlGender", "MALE");
}
} else if (language.equals("ar-xa")) {
// Arabic
if (gender == Gender.FEMALE) {
params.put("name", "ar-XA-Wavenet-A");
params.put("ssmlGender", "FEMALE");
} else {
params.put("name", "ar-XA-Standard-B");
params.put("ssmlGender", "MALE");
}
} else {
throw new IllegalArgumentException("Unsupported language code: " + language);
}

AudioResponse resModel = (AudioResponse) wrapper.generateSpeech(params);
decodedAudio = AudioHelper.decode(resModel.getAudioContent());
Expand Down
2 changes: 1 addition & 1 deletion sample_code/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</attributes>
</classpathentry>
<classpathentry kind="lib" path="jars/gson-2.10.1.jar"/>
<classpathentry kind="lib" path="jars/intellijava.core-0.8.0.jar"/>
<classpathentry kind="lib" path="jars/intellijava.core-0.8.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file removed sample_code/jars/intellijava.core-0.8.0.jar
Binary file not shown.
Binary file added sample_code/jars/intellijava.core-0.8.1.jar
Binary file not shown.
29 changes: 29 additions & 0 deletions sample_code/src/com/intelliJava/test/GoogleApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public static void main(String[] args) {

tryGoogleSpeechModel(apiKey);

System.out.print("Check the temp forlder for the generated audio.");

} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -56,5 +58,32 @@ private static void tryGoogleSpeechModel(String apiKey) throws IOException {
AudioHelper.saveTempAudio(decodedAudio);

}

/**
* Generate speech from text using google API.
*
* To use this model:
* 1- Go to console.cloud.google.com.
* 2- Enable "Cloud Text-to-Speech API" from APIs Services.
* 3- Generate API key from APIs and services Credentials page.
*
* @param apiKey
* @throws IOException
*/
private static void tryGermanSpeechModel(String apiKey) throws IOException {


RemoteSpeechModel model = new RemoteSpeechModel(apiKey, SpeechModels.google);

Text2SpeechInput input = new Text2SpeechInput.Builder("Hallo, ich bin Intelligent Java.").build();

// get the audio bytes
// you can play it using libraries like javafx
byte[] decodedAudio = model.generateGermanText(input);

// save temporary audio file
AudioHelper.saveTempAudio(decodedAudio);

}

}