diff --git a/source/transcribelambda/gradle/src/main/java/com/amazonaws/transcribestreaming/cli/TranscribeStreamingDemoApp.java b/source/transcribelambda/gradle/src/main/java/com/amazonaws/transcribestreaming/cli/TranscribeStreamingDemoApp.java index 02398248..d9e6ca2a 100644 --- a/source/transcribelambda/gradle/src/main/java/com/amazonaws/transcribestreaming/cli/TranscribeStreamingDemoApp.java +++ b/source/transcribelambda/gradle/src/main/java/com/amazonaws/transcribestreaming/cli/TranscribeStreamingDemoApp.java @@ -65,10 +65,22 @@ public static void main(String args[]) throws URISyntaxException, ExecutionExcep Gson gson = new Gson(); ResponseObject output; - output = getTextFromURL("http://bank-test2.s3.amazonaws.com/testfile.pcm", "testingvocabulary"); - String printout = gson.toJson(output); - System.out.println(printout); + // @see https://docs.aws.amazon.com/transcribe/latest/dg/API_StartTranscriptionJob.html#API_StartTranscriptionJob_RequestSyntax + // @todo: get the input language code from argument + String inputLanguageCode = LanguageCode.EN_US.toString(); + output = getTextFromURL("http://bank-test2.s3.amazonaws.com/testfile.pcm", "testingvocabulary", inputLanguageCode); + + for (String languageCode : new String[] { "en-US", "es-US", "pt-BR" }) { + if (languageCode == inputLanguageCode) { + continue; + } + + // @todo: perform translation in other languages + + String printout = gson.toJson(output); + System.out.println(printout); + } } enum JobType { @@ -85,7 +97,7 @@ enum JobType { } - public static ResponseObject getTextFromURL(String InputURL, String customVocabulary) throws URISyntaxException, ExecutionException, InterruptedException { + public static ResponseObject getTextFromURL(String InputURL, String customVocabulary, String languageCode) throws URISyntaxException, ExecutionException, InterruptedException { /** * Create Transcribe streaming client, using AWS credentials and us-east-1 endpoint */ @@ -116,7 +128,7 @@ public static ResponseObject getTextFromURL(String InputURL, String customVocabu */ CompletableFuture result = client.startStreamTranscription( - getRequest(16_000, customVocabulary), + getRequest(16_000, customVocabulary, languageCode), new AudioStreamPublisher(getStreamFromFileUrl(InputURL)), getResponseHandler()); @@ -193,16 +205,16 @@ private static AwsCredentialsProvider getCredentials() { return DefaultCredentialsProvider.create(); } - private static StartStreamTranscriptionRequest getRequest(Integer mediaSampleRateHertz, String customVocabulary) { + private static StartStreamTranscriptionRequest getRequest(Integer mediaSampleRateHertz, String customVocabulary, String languageCode) { if(customVocabulary == null || customVocabulary.equals("")){ return StartStreamTranscriptionRequest.builder() - .languageCode(LanguageCode.EN_US.toString()) + .languageCode(languageCode) .mediaEncoding(MediaEncoding.PCM) .mediaSampleRateHertz(mediaSampleRateHertz) .build(); }else { return StartStreamTranscriptionRequest.builder() - .languageCode(LanguageCode.EN_US.toString()) + .languageCode(languageCode) .mediaEncoding(MediaEncoding.PCM) .mediaSampleRateHertz(mediaSampleRateHertz) .vocabularyName(customVocabulary)