diff --git a/README.md b/README.md index da9a404..7adfeff 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

- + @@ -40,23 +40,23 @@ Maven: io.github.barqawiz intellijava.core - 0.8.0 + 0.8.2 ``` 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): diff --git a/core/com.intellijava.core/pom.xml b/core/com.intellijava.core/pom.xml index fa56258..039ebd2 100644 --- a/core/com.intellijava.core/pom.xml +++ b/core/com.intellijava.core/pom.xml @@ -6,7 +6,7 @@ io.github.barqawiz intellijava.core - 0.8.0 + 0.8.2 Intellijava IntelliJava allows java developers to easily integrate with the latest language models, image generation, and deep learning frameworks. diff --git a/core/com.intellijava.core/src/main/java/com/intellijava/core/controller/RemoteSpeechModel.java b/core/com.intellijava.core/src/main/java/com/intellijava/core/controller/RemoteSpeechModel.java index a2df3ff..5813bd9 100644 --- a/core/com.intellijava.core/src/main/java/com/intellijava/core/controller/RemoteSpeechModel.java +++ b/core/com.intellijava.core/src/main/java/com/intellijava/core/controller/RemoteSpeechModel.java @@ -110,9 +110,9 @@ public List 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. @@ -121,7 +121,101 @@ public List 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"); } @@ -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()); diff --git a/sample_code/.classpath b/sample_code/.classpath index bdba750..8a7476c 100644 --- a/sample_code/.classpath +++ b/sample_code/.classpath @@ -8,6 +8,6 @@ - + diff --git a/sample_code/jars/intellijava.core-0.8.0.jar b/sample_code/jars/intellijava.core-0.8.0.jar deleted file mode 100644 index 4737b5b..0000000 Binary files a/sample_code/jars/intellijava.core-0.8.0.jar and /dev/null differ diff --git a/sample_code/jars/intellijava.core-0.8.1.jar b/sample_code/jars/intellijava.core-0.8.1.jar new file mode 100644 index 0000000..560fde0 Binary files /dev/null and b/sample_code/jars/intellijava.core-0.8.1.jar differ diff --git a/sample_code/src/com/intelliJava/test/GoogleApp.java b/sample_code/src/com/intelliJava/test/GoogleApp.java index b25b457..3e6b8ae 100644 --- a/sample_code/src/com/intelliJava/test/GoogleApp.java +++ b/sample_code/src/com/intelliJava/test/GoogleApp.java @@ -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(); } @@ -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); + + } }