Skip to content

Speech api changes #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Jul 12, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
89f445c
renamed from recognize to streaming recognize
puneithk Jul 3, 2016
1408b15
added v1beta1 proto
puneithk Jul 3, 2016
6ac06c5
added long running operation
puneithk Jul 4, 2016
34f300c
made changes to the script
puneithk Jul 4, 2016
259ed6a
renamed to sync recognize client
puneithk Jul 4, 2016
4415993
added sync changes and test
puneithk Jul 4, 2016
3892470
added sync changes and test
puneithk Jul 4, 2016
e1516d2
made changes to script and tests
puneithk Jul 4, 2016
ed629b6
deleted
puneithk Jul 4, 2016
20e6b88
made sync work
puneithk Jul 4, 2016
6f513ca
added async
puneithk Jul 4, 2016
f221210
added async samples
puneithk Jul 5, 2016
f9ac582
added async response unpack
puneithk Jul 5, 2016
2b949f6
fixed formatting
puneithk Jul 5, 2016
cecb3b9
removed function
puneithk Jul 11, 2016
f0e8755
removed stub and performed google java formatter
puneithk Jul 11, 2016
03b5c76
modified comment
puneithk Jul 11, 2016
c3b811e
applied DIP for channel
puneithk Jul 11, 2016
e81d249
DIP for channel
puneithk Jul 11, 2016
3976813
removed header comments
puneithk Jul 11, 2016
e56ffc9
ran google java format
puneithk Jul 11, 2016
e47d295
renamed to examples
puneithk Jul 11, 2016
e84a63f
moved to com.examples.cloud.speech
puneithk Jul 11, 2016
a2daba0
renamed to com.examples.cloud.speech
puneithk Jul 11, 2016
9e0563c
fixed path
puneithk Jul 11, 2016
5ba3e19
moved to examples for test
puneithk Jul 11, 2016
e957cd3
moved to examples
puneithk Jul 11, 2016
115bbf8
fixed path
puneithk Jul 11, 2016
e7fd065
added license
puneithk Jul 11, 2016
01a7fa8
moved proto
puneithk Jul 12, 2016
b5bacda
added proto source dir
puneithk Jul 12, 2016
5a6d2ca
added that sample in beta
puneithk Jul 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixed formatting
  • Loading branch information
puneithk committed Jul 6, 2016
commit 2b949f62d0f2f71e7e6d5a2b9c0c28b52354aec0
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new samples we have been using com.example package instead of com.google. This is to make it more clear to the user that they can change the package to match their own project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure already existed. I didn't mess up with the package name. Change it still?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about pinging on the package name, it looks like whom ever reviewed the first version wasn't on the Java team. :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lesv @tswast Its common to put company name in the package even samples. This is google code so why not? https://github.com/linkedin/api-get-started/tree/master/java/src/com/linkedin/sample

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See RFC 2606


import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest;
import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse;
import com.google.cloud.speech.v1beta1.RecognitionAudio;
import com.google.cloud.speech.v1beta1.RecognitionConfig;
import com.google.cloud.speech.v1beta1.RecognitionConfig.AudioEncoding;
import com.google.cloud.speech.v1beta1.SpeechGrpc;
import com.google.cloud.speech.v1beta1.AsyncRecognizeRequest;
import com.google.cloud.speech.v1beta1.AsyncRecognizeResponse;
import com.google.protobuf.TextFormat;

import com.google.longrunning.GetOperationRequest;
import com.google.longrunning.Operation;
Expand Down Expand Up @@ -79,7 +78,7 @@ public class AsyncRecognizeClient {

private final ManagedChannel channel;
private final SpeechGrpc.SpeechBlockingStub stub;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is stub a term of art for speech recognition that I'm unaware of? Why stub?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's in this list you should explain why a stub is part of our code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stub is a gRPC term (inherited from stubby, it's predecessor). Client would be a better name, probably.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using them? Shouldn't the name be clearer for what we expose to users?

private final OperationsGrpc.OperationsBlockingStub op;
private final OperationsGrpc.OperationsBlockingStub statusStub;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same Q here?


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

logger.info("Created stub for " + host + ":" + port);
}
Expand Down Expand Up @@ -130,33 +129,36 @@ public void recognize() {
.setAudio(audio)
.build();

Operation operation, status;
Operation operation;
Operation status;
try {
operation = stub.asyncRecognize(request);

//Print the long running operation handle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Space before Print after //.

logger.log(Level.INFO, String.format("Operation handle: %s, URI: %s", operation.getName(),
input.toString()));
input.toString()));
} catch (StatusRuntimeException e) {
logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
return;
}

while(true) {
while (true) {
try {
logger.log(Level.INFO, "Waiting 2s for operation, {0} processing...", operation.getName());
Thread.sleep(2000);
GetOperationRequest operationReq = GetOperationRequest.newBuilder()
.setName(operation.getName())
.build();
status = op.getOperation(
status = statusStub.getOperation(
GetOperationRequest.newBuilder()
.setName(operation.getName())
.build()
);

if(status.getDone()) break;
}catch(Exception ex) {
if (status.getDone()) {
break;
}
} catch (Exception ex) {
logger.log(Level.WARNING, ex.getMessage());
}
}
Expand All @@ -165,7 +167,7 @@ public void recognize() {
AsyncRecognizeResponse asyncRes = status.getResponse().unpack(AsyncRecognizeResponse.class);

logger.info("Received response: " + asyncRes);
} catch(com.google.protobuf.InvalidProtocolBufferException ex) {
} catch (com.google.protobuf.InvalidProtocolBufferException ex) {
logger.log(Level.WARNING, "Unpack error, {0}",ex.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class RecognitionAudioFactory {
public static RecognitionAudio createRecognitionAudio(URI uri)
throws IOException {
if (uri.getScheme() == null) {
uri = new File(uri.toString()).toURI();
Path path = Paths.get(uri);
return audioFromBytes(Files.readAllBytes(path));
uri = new File(uri.toString()).toURI();
Path path = Paths.get(uri);
return audioFromBytes(Files.readAllBytes(path));
} else if (uri.getScheme().equals(FILE_SCHEME)) {
Path path = Paths.get(uri);
return audioFromBytes(Files.readAllBytes(path));
Expand Down