diff --git a/backend-java/app/bin/main/biz/readmylegal/backend/RequestHttp.class b/backend-java/app/bin/main/biz/readmylegal/backend/RequestHttp.class index 8e01eb4..eb3c0e8 100644 Binary files a/backend-java/app/bin/main/biz/readmylegal/backend/RequestHttp.class and b/backend-java/app/bin/main/biz/readmylegal/backend/RequestHttp.class differ diff --git a/backend-java/app/bin/main/biz/readmylegal/backend/TextToSpeech.class b/backend-java/app/bin/main/biz/readmylegal/backend/TextToSpeech.class index 3cc6004..b78dc2e 100644 Binary files a/backend-java/app/bin/main/biz/readmylegal/backend/TextToSpeech.class and b/backend-java/app/bin/main/biz/readmylegal/backend/TextToSpeech.class differ diff --git a/backend-java/app/build.gradle b/backend-java/app/build.gradle index 5d7a71d..85d9997 100644 --- a/backend-java/app/build.gradle +++ b/backend-java/app/build.gradle @@ -13,12 +13,24 @@ plugins { id "com.github.johnrengelman.shadow" version "8.1.1" } +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + repositories { // Use Maven Central for resolving dependencies. mavenCentral() } dependencies { + + // https://mvnrepository.com/artifact/org.slf4j/slf4j-simple + implementation 'org.slf4j:slf4j-simple:2.0.9' + + + // Use JUnit Jupiter for testing. testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1' @@ -35,6 +47,11 @@ dependencies { //https://cloud.google.com/text-to-speech/docs/create-audio-text-client-libraries#client-libraries-install-java implementation 'com.google.cloud:google-cloud-texttospeech:2.28.0' + + // https://mvnrepository.com/artifact/org.slf4j/slf4j-api + implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6' + // https://mvnrepository.com/artifact/org.slf4j/slf4j-api + implementation 'org.slf4j:slf4j-api:1.6.6' } diff --git a/backend-java/app/output.wav b/backend-java/app/output.wav new file mode 100644 index 0000000..700fd43 Binary files /dev/null and b/backend-java/app/output.wav differ diff --git a/backend-java/app/src/main/java/biz/readmylegal/backend/App.java b/backend-java/app/src/main/java/biz/readmylegal/backend/App.java index 9156375..cc34c35 100644 --- a/backend-java/app/src/main/java/biz/readmylegal/backend/App.java +++ b/backend-java/app/src/main/java/biz/readmylegal/backend/App.java @@ -39,6 +39,7 @@ public void stop() { public static void main(String[] args) throws Exception { // Args: port password tokenpath + /* App app = new App(Integer.parseInt(args[0]), args[1], new File(args[2])); app.start(); System.out.println("Listening on 127.0.0.1:" + app.getPort()); @@ -47,11 +48,19 @@ public static void main(String[] args) throws Exception { System.out.println("Closing server, please wait..."); app.stop(); System.out.println("Have a nice day!"); - + */ + //RequestHttp.test2(); //Speech to text //RequestHttp.test2(); //Text to Speech - // TextToSpeech.textToSpeech(); + String text = RequestHttp.test2(); + + System.out.println(text); + System.out.println(""); + String twoFalf = text.substring(0, 4900); + + // String finalText = "Hello World."; + TextToSpeech.LongtextToSpeech(twoFalf); } private static void awaitExit() { diff --git a/backend-java/app/src/main/java/biz/readmylegal/backend/RequestHttp.java b/backend-java/app/src/main/java/biz/readmylegal/backend/RequestHttp.java index cf6ba80..47e0cde 100644 --- a/backend-java/app/src/main/java/biz/readmylegal/backend/RequestHttp.java +++ b/backend-java/app/src/main/java/biz/readmylegal/backend/RequestHttp.java @@ -1,5 +1,6 @@ package biz.readmylegal.backend; +import java.io.File; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -7,14 +8,18 @@ import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.nio.file.Files; -import java.io.File; -import java.lang.Thread; import com.fasterxml.jackson.databind.ObjectMapper; public class RequestHttp { - public static void test2() throws Exception{ + public String myString; + + + public static String test2() throws Exception{ + + String myString; + Transcript transcript = new Transcript(); transcript.setAudio_url("https://drive.google.com/uc?export=download&id=13VKm5sF3kC5_99uyDPrY9VFSwuIwpBXV"); @@ -22,12 +27,12 @@ public static void test2() throws Exception{ //convert transcript inot Json ObjectMapper objectmapper = new ObjectMapper(); - + //System.out.println("I am Here"); String json = objectmapper.writeValueAsString(transcript); //System.out.println("I am here Right NOW "); //pring the Set audio Url System.out.println(); - System.out.println(json); + //System.out.println(json); System.out.println(); @@ -65,6 +70,8 @@ public static void test2() throws Exception{ transcript = objectmapper.readValue(getResponse.body(), Transcript.class); + + System.out.println(transcript.getStatus()); if("completed".equals(transcript.getStatus() )|| "error".equals(transcript.getStatus())){ @@ -75,9 +82,17 @@ public static void test2() throws Exception{ } System.out.println("Transcription Completed "); - System.out.println(transcript.getText()); + //System.out.println(transcript.getText()); + + myString = transcript.getText(); + return myString; + } + + + void ClassA (String myString) { + this.myString = myString; } } diff --git a/backend-java/app/src/main/java/biz/readmylegal/backend/TextToSpeech.java b/backend-java/app/src/main/java/biz/readmylegal/backend/TextToSpeech.java index 430d1c1..3e1c943 100644 --- a/backend-java/app/src/main/java/biz/readmylegal/backend/TextToSpeech.java +++ b/backend-java/app/src/main/java/biz/readmylegal/backend/TextToSpeech.java @@ -1,15 +1,13 @@ package biz.readmylegal.backend; -// Imports the Google Cloud client library -import com.google.cloud.texttospeech.v1.AudioConfig; -import com.google.cloud.texttospeech.v1.AudioEncoding; -import com.google.cloud.texttospeech.v1.SsmlVoiceGender; -import com.google.cloud.texttospeech.v1.SynthesisInput; -import com.google.cloud.texttospeech.v1.SynthesizeSpeechResponse; -import com.google.cloud.texttospeech.v1.TextToSpeechClient; -import com.google.cloud.texttospeech.v1.VoiceSelectionParams; +import java.io.FileOutputStream; +import java.io.IOException; + +import com.google.cloud.texttospeech.v1.*; import com.google.protobuf.ByteString; +import com.google.protobuf.Duration; +import com.google.protobuf.TextFormat; import java.io.FileOutputStream; import java.io.OutputStream; @@ -17,16 +15,44 @@ + + + public class TextToSpeech { + /* + + public static void ShorttextToSpeech(String finalText) throws IOException{ + + + Version 1 Long Test. + TextToSpeechClient client = TextToSpeechClient.create(); + //Call the synthesizeAudio() method on the client object. + + + SynthesizeSpeechRequest request = new SynthesizeSpeechRequest(); - public static void textToSpeech() throws Exception{ + request.setText("Hello, world!"); + request.setOutputFormat("mp3"); + request.setAudioEncoding("LINEAR16"); + request.setSampleRateHertz(16000); + SynthesizeSpeechResponse response = client.synthesizeSpeech(request); + // Get the synthesized audio. + byte[] audioContent = response.getAudioContent(); + + FileOutputStream outputStream = new FileOutputStream("output.mp3"); + outputStream.write(audioContent); + outputStream.close(); + + + //short text. try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { // Set the text input to be synthesized - SynthesisInput input = SynthesisInput.newBuilder().setText("I love you!").build(); + SynthesisInput input = SynthesisInput.newBuilder().setText(finalText).build(); // Build the voice request, select the language code ("en-US") and the ssml voice gender // ("neutral") + VoiceSelectionParams voice = VoiceSelectionParams.newBuilder() .setLanguageCode("en-US") @@ -53,6 +79,48 @@ public static void textToSpeech() throws Exception{ } + } +*/ + + + + + + + + public static void LongtextToSpeech(String finalText) throws Exception{ + try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { + // Specify the text to be synthesized + //String inputText = "This is a long text to be converted to speech."; + + // Configure the synthesis request + SynthesisInput input = SynthesisInput.newBuilder().setText(finalText).build(); + VoiceSelectionParams voice = + VoiceSelectionParams.newBuilder() + .setLanguageCode("en-US") + .setName("en-US-Wavenet-D") + .build(); + AudioConfig audioConfig = + AudioConfig.newBuilder() + .setAudioEncoding(AudioEncoding.LINEAR16) + .setSpeakingRate(1.0) + .setPitch(0.0) + .setVolumeGainDb(0.0) + .setSampleRateHertz(16000) + .build(); + + // Send the request to the Text-to-Speech API + SynthesizeSpeechResponse response = + textToSpeechClient.synthesizeSpeech(input, voice, audioConfig); + + // Save the synthesized audio to a file + try (OutputStream out = new FileOutputStream("output.wav")) { + ByteString audioContents = response.getAudioContent(); + out.write(audioContents.toByteArray()); + } + } + + } diff --git a/backend-java/output.mp3 b/backend-java/output.mp3 index a169728..7e75bf5 100644 Binary files a/backend-java/output.mp3 and b/backend-java/output.mp3 differ