Skip to content

Commit

Permalink
configure google service account
Browse files Browse the repository at this point in the history
  • Loading branch information
Maleehak committed Apr 11, 2024
1 parent 7bfc3e2 commit c7b9fb5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.mvn/wrapper
backend/target/
.idea/
.idea/
google-api-credentials.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Slf4j
public class BriefMeApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args){
SpringApplication.run(BriefMeApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,37 @@

import com.example.BriefMe.service.client.AudioToTextConverter;
import com.example.BriefMe.util.SpeechRecognitionTask;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.speech.v1.SpeechClient;
import com.google.cloud.speech.v1.SpeechSettings;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class AudioToTextConverterImpl implements AudioToTextConverter {

@Value("${google.api.credentials.location}")
private String credentialsPath;

public String covertAudioToText(String audioFile){

try (SpeechClient speechClient = SpeechClient.create()) {
try{
CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(
ServiceAccountCredentials.fromStream(new FileInputStream(credentialsPath)));

SpeechSettings settings = SpeechSettings.newBuilder().setCredentialsProvider(credentialsProvider).build();
SpeechClient speechClient = SpeechClient.create(settings);

log.info("Loading the audio file into memory...");

Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
spring.application.name=BriefMe
google.api.credentials.location=google-api-credentials.json

0 comments on commit c7b9fb5

Please sign in to comment.