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

Attempt to handle multiple languages at TranscribeStreamingDemoApp #1

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
*/
Expand Down Expand Up @@ -116,7 +128,7 @@ public static ResponseObject getTextFromURL(String InputURL, String customVocabu
*/

CompletableFuture<Void> result = client.startStreamTranscription(
getRequest(16_000, customVocabulary),
getRequest(16_000, customVocabulary, languageCode),
new AudioStreamPublisher(getStreamFromFileUrl(InputURL)),
getResponseHandler());

Expand Down Expand Up @@ -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)
Expand Down