Skip to content

Commit 2b949f6

Browse files
committed
fixed formatting
1 parent f9ac582 commit 2b949f6

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/AsyncRecognizeClient.java

+15-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
// Client that sends audio to Speech.AsyncRecognize via gRPC and returns transcription.
17+
// Client that sends audio to Speech.AsyncRecognize via gRPC and returns longrunning operation.
18+
// The results are received via the google.longrunning.Operations interface.
1819
//
1920
// Uses a service account for OAuth2 authentication, which you may obtain at
2021
// https://console.developers.google.com
@@ -26,14 +27,12 @@
2627
package com.google.cloud.speech.grpc.demos;
2728

2829
import com.google.auth.oauth2.GoogleCredentials;
30+
import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest;
2931
import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse;
3032
import com.google.cloud.speech.v1beta1.RecognitionAudio;
3133
import com.google.cloud.speech.v1beta1.RecognitionConfig;
3234
import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding;
3335
import com.google.cloud.speech.v1beta1.SpeechGrpc;
34-
import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest;
35-
import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse;
36-
import com.google.protobuf.TextFormat;
3736

3837
import com.google.longrunning.GetOperationRequest;
3938
import com.google.longrunning.Operation;
@@ -79,7 +78,7 @@ public class AsyncRecognizeClient {
7978

8079
private final ManagedChannel channel;
8180
private final SpeechGrpc.SpeechBlockingStub stub;
82-
private final OperationsGrpc.OperationsBlockingStub op;
81+
private final OperationsGrpc.OperationsBlockingStub statusStub;
8382

8483
/**
8584
* Construct client connecting to Cloud Speech server at {@code host:port}.
@@ -98,7 +97,7 @@ public AsyncRecognizeClient(String host, int port, URI input, int samplingRate)
9897
.intercept(new ClientAuthInterceptor(creds, Executors.newSingleThreadExecutor()))
9998
.build();
10099
stub = SpeechGrpc.newBlockingStub(channel);
101-
op = OperationsGrpc.newBlockingStub(channel);
100+
statusStub = OperationsGrpc.newBlockingStub(channel);
102101

103102
logger.info("Created stub for " + host + ":" + port);
104103
}
@@ -130,33 +129,36 @@ public void recognize() {
130129
.setAudio(audio)
131130
.build();
132131

133-
Operation operation, status;
132+
Operation operation;
133+
Operation status;
134134
try {
135135
operation = stub.asyncRecognize(request);
136136

137137
//Print the long running operation handle
138138
logger.log(Level.INFO, String.format("Operation handle: %s, URI: %s", operation.getName(),
139-
input.toString()));
139+
input.toString()));
140140
} catch (StatusRuntimeException e) {
141141
logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
142142
return;
143143
}
144144

145-
while(true) {
145+
while (true) {
146146
try {
147147
logger.log(Level.INFO, "Waiting 2s for operation, {0} processing...", operation.getName());
148148
Thread.sleep(2000);
149149
GetOperationRequest operationReq = GetOperationRequest.newBuilder()
150150
.setName(operation.getName())
151151
.build();
152-
status = op.getOperation(
152+
status = statusStub.getOperation(
153153
GetOperationRequest.newBuilder()
154154
.setName(operation.getName())
155155
.build()
156156
);
157157

158-
if(status.getDone()) break;
159-
}catch(Exception ex) {
158+
if (status.getDone()) {
159+
break;
160+
}
161+
} catch (Exception ex) {
160162
logger.log(Level.WARNING, ex.getMessage());
161163
}
162164
}
@@ -165,7 +167,7 @@ public void recognize() {
165167
AsyncRecognizeResponse asyncRes = status.getResponse().unpack(AsyncRecognizeResponse.class);
166168

167169
logger.info("Received response: " + asyncRes);
168-
} catch(com.google.protobuf.InvalidProtocolBufferException ex) {
170+
} catch (com.google.protobuf.InvalidProtocolBufferException ex) {
169171
logger.log(Level.WARNING, "Unpack error, {0}",ex.getMessage());
170172
}
171173
}

speech/grpc/src/main/java/com/google/cloud/speech/grpc/demos/RecognitionAudioFactory.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public class RecognitionAudioFactory {
4545
public static RecognitionAudio createRecognitionAudio(URI uri)
4646
throws IOException {
4747
if (uri.getScheme() == null) {
48-
uri = new File(uri.toString()).toURI();
49-
Path path = Paths.get(uri);
50-
return audioFromBytes(Files.readAllBytes(path));
48+
uri = new File(uri.toString()).toURI();
49+
Path path = Paths.get(uri);
50+
return audioFromBytes(Files.readAllBytes(path));
5151
} else if (uri.getScheme().equals(FILE_SCHEME)) {
5252
Path path = Paths.get(uri);
5353
return audioFromBytes(Files.readAllBytes(path));

0 commit comments

Comments
 (0)