Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final push. #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Binary file modified backend-java/app/bin/main/biz/readmylegal/backend/RequestHttp.class
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions backend-java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'

}

Expand Down
Binary file added backend-java/app/output.wav
Binary file not shown.
13 changes: 11 additions & 2 deletions backend-java/app/src/main/java/biz/readmylegal/backend/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
package biz.readmylegal.backend;

import java.io.File;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
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");


//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();


Expand Down Expand Up @@ -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())){
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
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;








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")
Expand All @@ -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());
}
}



}

Expand Down
Binary file modified backend-java/output.mp3
Binary file not shown.