1212import software .amazon .awssdk .regions .Region ;
1313import software .amazon .awssdk .services .transcribestreaming .TranscribeStreamingAsyncClient ;
1414import software .amazon .awssdk .services .transcribestreaming .model .*;
15- import javax .sound .sampled .*;
16- import java .io .*;
15+
16+ import javax .sound .sampled .AudioFormat ;
17+ import javax .sound .sampled .AudioInputStream ;
18+ import javax .sound .sampled .AudioSystem ;
19+ import javax .sound .sampled .DataLine ;
20+ import javax .sound .sampled .LineUnavailableException ;
21+ import javax .sound .sampled .TargetDataLine ;
22+ import java .io .IOException ;
23+ import java .io .InputStream ;
24+ import java .io .PrintWriter ;
25+ import java .io .StringWriter ;
26+ import java .io .UncheckedIOException ;
1727import java .net .URISyntaxException ;
1828import java .nio .ByteBuffer ;
1929import java .util .List ;
@@ -28,7 +38,7 @@ public class TranscribeStreamingDemoApp {
2838 private static final Region REGION = Region .US_EAST_1 ;
2939 private static TranscribeStreamingAsyncClient client ;
3040
31- public static void main (String args [] )
41+ public static void main (String [] args )
3242 throws URISyntaxException , ExecutionException , InterruptedException , LineUnavailableException {
3343
3444 client = TranscribeStreamingAsyncClient .builder ()
@@ -85,7 +95,7 @@ private static StartStreamTranscriptionResponseHandler getResponseHandler() {
8595 System .out .println (e .getMessage ());
8696 StringWriter sw = new StringWriter ();
8797 e .printStackTrace (new PrintWriter (sw ));
88- System .out .println ("Error Occurred: " + sw . toString () );
98+ System .out .println ("Error Occurred: " + sw );
8999 })
90100 .onComplete (() -> {
91101 System .out .println ("=== All records stream successfully ===" );
@@ -101,19 +111,10 @@ private static StartStreamTranscriptionResponseHandler getResponseHandler() {
101111 .build ();
102112 }
103113
104- private InputStream getStreamFromFile (String audioFileName ) {
105- try {
106- File inputFile = new File (getClass ().getClassLoader ().getResource (audioFileName ).getFile ());
107- InputStream audioStream = new FileInputStream (inputFile );
108- return audioStream ;
109- } catch (FileNotFoundException e ) {
110- throw new RuntimeException (e );
111- }
112- }
113-
114+
114115 private static class AudioStreamPublisher implements Publisher <AudioStream > {
115- private final InputStream inputStream ;
116116 private static Subscription currentSubscription ;
117+ private final InputStream inputStream ;
117118
118119 private AudioStreamPublisher (InputStream inputStream ) {
119120 this .inputStream = inputStream ;
@@ -122,22 +123,22 @@ private AudioStreamPublisher(InputStream inputStream) {
122123 @ Override
123124 public void subscribe (Subscriber <? super AudioStream > s ) {
124125
125- if (this . currentSubscription == null ) {
126- this . currentSubscription = new SubscriptionImpl (s , inputStream );
126+ if (currentSubscription == null ) {
127+ currentSubscription = new SubscriptionImpl (s , inputStream );
127128 } else {
128- this . currentSubscription .cancel ();
129- this . currentSubscription = new SubscriptionImpl (s , inputStream );
129+ currentSubscription .cancel ();
130+ currentSubscription = new SubscriptionImpl (s , inputStream );
130131 }
131132 s .onSubscribe (currentSubscription );
132133 }
133134 }
134135
135136 public static class SubscriptionImpl implements Subscription {
136- private static final int CHUNK_SIZE_IN_BYTES = 1024 * 1 ;
137+ private static final int CHUNK_SIZE_IN_BYTES = 1024 ;
137138 private final Subscriber <? super AudioStream > subscriber ;
138139 private final InputStream inputStream ;
139- private ExecutorService executor = Executors .newFixedThreadPool (1 );
140- private AtomicLong demand = new AtomicLong (0 );
140+ private final ExecutorService executor = Executors .newFixedThreadPool (1 );
141+ private final AtomicLong demand = new AtomicLong (0 );
141142
142143 SubscriptionImpl (Subscriber <? super AudioStream > s , InputStream inputStream ) {
143144 this .subscriber = s ;
0 commit comments