Search in sources :

Example 1 with TranscribeStreamingAsyncClient

use of software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient 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);
    }
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) TargetDataLine(javax.sound.sampled.TargetDataLine) LanguageCode(software.amazon.awssdk.services.transcribestreaming.model.LanguageCode) MediaEncoding(software.amazon.awssdk.services.transcribestreaming.model.MediaEncoding) TranscriptEvent(software.amazon.awssdk.services.transcribestreaming.model.TranscriptEvent) AudioFormat(javax.sound.sampled.AudioFormat) DataLine(javax.sound.sampled.DataLine) TranscribeStreamingAsyncClient(software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient) StartStreamTranscriptionRequest(software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionRequest) AudioInputStream(javax.sound.sampled.AudioInputStream) Region(software.amazon.awssdk.regions.Region) TranscribeStreamingException(software.amazon.awssdk.services.transcribestreaming.model.TranscribeStreamingException) AudioSystem(javax.sound.sampled.AudioSystem) StartStreamTranscriptionResponseHandler(software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionResponseHandler) TranscriptEvent(software.amazon.awssdk.services.transcribestreaming.model.TranscriptEvent) StartStreamTranscriptionRequest(software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionRequest) StartStreamTranscriptionResponseHandler(software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionResponseHandler) TranscribeStreamingException(software.amazon.awssdk.services.transcribestreaming.model.TranscribeStreamingException) TargetDataLine(javax.sound.sampled.TargetDataLine)

Example 2 with TranscribeStreamingAsyncClient

use of software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient in project aws-doc-sdk-examples by awsdocs.

the class BidirectionalStreaming method main.

public static void main(String[] args) throws Exception {
    Region region = Region.US_WEST_2;
    TranscribeStreamingAsyncClient client = TranscribeStreamingAsyncClient.builder().region(region).build();
    convertAudio(client);
}
Also used : TranscribeStreamingAsyncClient(software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient) Region(software.amazon.awssdk.regions.Region)

Aggregations

Region (software.amazon.awssdk.regions.Region)2 TranscribeStreamingAsyncClient (software.amazon.awssdk.services.transcribestreaming.TranscribeStreamingAsyncClient)2 AudioFormat (javax.sound.sampled.AudioFormat)1 AudioInputStream (javax.sound.sampled.AudioInputStream)1 AudioSystem (javax.sound.sampled.AudioSystem)1 DataLine (javax.sound.sampled.DataLine)1 TargetDataLine (javax.sound.sampled.TargetDataLine)1 LanguageCode (software.amazon.awssdk.services.transcribestreaming.model.LanguageCode)1 MediaEncoding (software.amazon.awssdk.services.transcribestreaming.model.MediaEncoding)1 StartStreamTranscriptionRequest (software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionRequest)1 StartStreamTranscriptionResponseHandler (software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionResponseHandler)1 TranscribeStreamingException (software.amazon.awssdk.services.transcribestreaming.model.TranscribeStreamingException)1 TranscriptEvent (software.amazon.awssdk.services.transcribestreaming.model.TranscriptEvent)1