use of software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionRequest 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);
}
}
use of software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionRequest in project aws-doc-sdk-examples by awsdocs.
the class StreamingRetryApp method main.
public static void main(String[] args) throws URISyntaxException, ExecutionException, InterruptedException, LineUnavailableException, FileNotFoundException {
/**
* Create Amazon Transcribe streaming retry client.
*/
TranscribeStreamingRetryClient client = new TranscribeStreamingRetryClient(EnvironmentVariableCredentialsProvider.create(), endpoint, region);
StartStreamTranscriptionRequest request = StartStreamTranscriptionRequest.builder().languageCode(language).mediaEncoding(encoding).mediaSampleRateHertz(sample_rate).build();
/**
* Start real-time speech recognition. The Amazon Transcribe streaming java client uses the Reactive-streams
* interface. For reference on Reactive-streams:
* https://github.com/reactive-streams/reactive-streams-jvm
*/
CompletableFuture<Void> result = client.startStreamTranscription(/**
* Request parameters. Refer to API documentation for details.
*/
request, /**
* Provide an input audio stream.
* For input from a microphone, use getStreamFromMic().
* For input from a file, use getStreamFromFile().
*/
new AudioStreamPublisher(new FileInputStream(new File("FileName"))), /**
* Object that defines the behavior on how to handle the stream
*/
new StreamTranscriptionBehaviorImpl());
/**
* Synchronous wait for stream to close, and close client connection
*/
result.get();
client.close();
}
Aggregations