// snippet-sourcedescription:[StreamingRetryApp.java is an application that demonstrates using the Amazon Transcribe retry client.]
// snippet-service:[transcribe]
// snippet-keyword:[Java]
// snippet-sourcesyntax:[java]
// snippet-keyword:[Amazon Transcribe]
// snippet-keyword:[Code Sample]
// snippet-keyword:[TranscribeStreamingAsyncClient]
// snippet-keyword:[StartStreamTranscriptionResponse]
// snippet-sourcetype:[snippet]
// snippet-sourcedate:[2019-01-10]
// snippet-sourceauthor:[AWS]
// snippet-start:[transcribe.java-streaming-retry-app]
/**
 * COPYRIGHT:
 * <p>
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.amazonaws.transcribestreaming;

import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.transcribestreaming.model.AudioStream;
import software.amazon.awssdk.services.transcribestreaming.model.LanguageCode;
import software.amazon.awssdk.services.transcribestreaming.model.StartStreamTranscriptionRequest;
import javax.sound.sampled.LineUnavailableException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import com.amazonaws.transcribestreaming.TranscribeStreamingDemoApp;


public class StreamingRetryApp {
    private static final String endpoint = "endpoint";
    private static final Region region = Region.US_EAST_1;
    private static final int sample_rate = 28800;
    private static final String encoding = " ";
    private static final String language = LanguageCode.EN_US.toString();

    public static void main(String args[]) throws URISyntaxException, ExecutionException, InterruptedException, LineUnavailableException, FileNotFoundException {
        /**
         * Create Transcribe streaming retry client using AWS credentials.
         */

        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 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();
    }

    private static class AudioStreamPublisher implements Publisher<AudioStream> {
        private final InputStream inputStream;
        private static Subscription currentSubscription;

        private AudioStreamPublisher(InputStream inputStream) {
            this.inputStream = inputStream;
        }

        @Override
        public void subscribe(Subscriber<? super AudioStream> s) {
            if (this.currentSubscription == null) {
                this.currentSubscription = new TranscribeStreamingDemoApp.SubscriptionImpl(s, inputStream);
            } else {
                this.currentSubscription.cancel();
                this.currentSubscription = new TranscribeStreamingDemoApp.SubscriptionImpl(s, inputStream);
            }
            s.onSubscribe(currentSubscription);
        }
    }
}
// snippet-end:[transcribe.java-streaming-retry-app]
@@ -505,89 +505,10 @@
 %5D%0D%0A/
-/ snippet-start:%5Btranscribe.java-streaming-retry-app%5D%0D%0A/**%0D%0A * COPYRIGHT:%0D%0A * %3Cp%3E
+**
 %0D%0A *
@@ -582,18 +582,27 @@
 %0D%0A *
- %3Cp%3E
 %0D%0A * 
-L
+This file is l
 icen
@@ -728,20 +728,16 @@
 License.
-%0D%0A *
  A copy 
@@ -738,16 +738,20 @@
  copy of
+%0D%0A *
  the Lic
@@ -768,28 +768,24 @@
 cated at%0D%0A *
- %3Cp%3E
 %0D%0A * http://
@@ -788,104 +788,41 @@
 p://
-www.apache.org/licenses/LICENSE-
+aws.amazon.com/apache
 2.0
+/
 %0D%0A *
- %3Cp%3E
 %0D%0A *
- or in the %22license%22 file accompanying this file.
  Thi
@@ -842,20 +842,16 @@
 tributed
-%0D%0A *
  on an %22
@@ -885,16 +885,20 @@
 NTIES OR
+%0D%0A *
  CONDITI
@@ -920,20 +920,16 @@
 , either
-%0D%0A *
  express
@@ -964,16 +964,20 @@
  for the
+%0D%0A *
  specifi
@@ -996,20 +996,16 @@
 overning
-%0D%0A *
  permiss
@@ -1045,16 +1045,20 @@
 cense.%0D%0A
+ *%0D%0A
  */%0D%0Apac
@@ -5067,8 +5067,10 @@
 try-app%5D
+%0D%0A

Update StreamingRetryApp.java