use of software.amazon.awssdk.services.transcribestreaming.model.LanguageCode in project aws-doc-sdk-examples by awsdocs.
the class BidirectionalStreaming method convertAudio.
// snippet-start:[transcribe.java2.bidir_streaming.main]
public static void convertAudio(TranscribeStreamingAsyncClient client) throws Exception {
try {
StartStreamTranscriptionRequest request = StartStreamTranscriptionRequest.builder().mediaEncoding(MediaEncoding.PCM).languageCode(LanguageCode.EN_US).mediaSampleRateHertz(16_000).build();
TargetDataLine mic = Microphone.get();
mic.start();
AudioStreamPublisher publisher = new AudioStreamPublisher(new AudioInputStream(mic));
StartStreamTranscriptionResponseHandler response = StartStreamTranscriptionResponseHandler.builder().subscriber(e -> {
TranscriptEvent event = (TranscriptEvent) e;
event.transcript().results().forEach(r -> r.alternatives().forEach(a -> System.out.println(a.transcript())));
}).build();
// Keeps Streaming until you end the Java program
client.startStreamTranscription(request, publisher, response);
} catch (TranscribeStreamingException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
Aggregations