@Generated(value="by GAPIC") public class SpeechApi extends Object implements AutoCloseable
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
SyncRecognizeResponse response = speechApi.syncRecognize(config, audio);
}
Note: close() needs to be called on the speechApi object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of SpeechSettings to create(). For example:
SpeechSettings speechSettings = SpeechSettings.defaultBuilder()
.provideChannelWith(myCredentials)
.build();
SpeechApi speechApi = SpeechApi.create(speechSettings);
| Modifier | Constructor and Description |
|---|---|
protected |
SpeechApi(SpeechSettings settings)
Constructs an instance of SpeechApi, using the given settings.
|
| Modifier and Type | Method and Description |
|---|---|
com.google.longrunning.Operation |
asyncRecognize(com.google.cloud.speech.v1beta1.AsyncRecognizeRequest request)
Perform asynchronous speech-recognition: receive results via the
google.longrunning.Operations interface.
|
com.google.longrunning.Operation |
asyncRecognize(com.google.cloud.speech.v1beta1.RecognitionConfig config,
com.google.cloud.speech.v1beta1.RecognitionAudio audio)
Perform asynchronous speech-recognition: receive results via the
google.longrunning.Operations interface.
|
com.google.api.gax.grpc.ApiCallable<com.google.cloud.speech.v1beta1.AsyncRecognizeRequest,com.google.longrunning.Operation> |
asyncRecognizeCallable()
Perform asynchronous speech-recognition: receive results via the
google.longrunning.Operations interface.
|
void |
close()
Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
cancelled.
|
static SpeechApi |
create()
Constructs an instance of SpeechApi with default settings.
|
static SpeechApi |
create(SpeechSettings settings)
Constructs an instance of SpeechApi, using the given settings.
|
SpeechSettings |
getSettings() |
com.google.cloud.speech.v1beta1.SyncRecognizeResponse |
syncRecognize(com.google.cloud.speech.v1beta1.RecognitionConfig config,
com.google.cloud.speech.v1beta1.RecognitionAudio audio)
Perform synchronous speech-recognition: receive results after all audio
has been sent and processed.
|
com.google.cloud.speech.v1beta1.SyncRecognizeResponse |
syncRecognize(com.google.cloud.speech.v1beta1.SyncRecognizeRequest request)
Perform synchronous speech-recognition: receive results after all audio
has been sent and processed.
|
com.google.api.gax.grpc.ApiCallable<com.google.cloud.speech.v1beta1.SyncRecognizeRequest,com.google.cloud.speech.v1beta1.SyncRecognizeResponse> |
syncRecognizeCallable()
Perform synchronous speech-recognition: receive results after all audio
has been sent and processed.
|
protected SpeechApi(SpeechSettings settings) throws IOException
IOExceptionpublic final SpeechSettings getSettings()
public static final SpeechApi create() throws IOException
IOExceptionpublic static final SpeechApi create(SpeechSettings settings) throws IOException
IOExceptionpublic final com.google.cloud.speech.v1beta1.SyncRecognizeResponse syncRecognize(com.google.cloud.speech.v1beta1.RecognitionConfig config, com.google.cloud.speech.v1beta1.RecognitionAudio audio)
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
SyncRecognizeResponse response = speechApi.syncRecognize(config, audio);
}
config - [Required] The `config` message provides information to the recognizer
that specifies how to process the request.audio - [Required] The audio data to be recognized.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.cloud.speech.v1beta1.SyncRecognizeResponse syncRecognize(com.google.cloud.speech.v1beta1.SyncRecognizeRequest request)
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
SyncRecognizeRequest request = SyncRecognizeRequest.newBuilder()
.setConfig(config)
.setAudio(audio)
.build();
SyncRecognizeResponse response = speechApi.syncRecognize(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.cloud.speech.v1beta1.SyncRecognizeRequest,com.google.cloud.speech.v1beta1.SyncRecognizeResponse> syncRecognizeCallable()
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
SyncRecognizeRequest request = SyncRecognizeRequest.newBuilder()
.setConfig(config)
.setAudio(audio)
.build();
ListenableFuture<SyncRecognizeResponse> future = speechApi.syncRecognizeCallable().futureCall(request);
// Do something
SyncRecognizeResponse response = future.get();
}
public final com.google.longrunning.Operation asyncRecognize(com.google.cloud.speech.v1beta1.RecognitionConfig config, com.google.cloud.speech.v1beta1.RecognitionAudio audio)
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
Operation response = speechApi.asyncRecognize(config, audio);
}
config - [Required] The `config` message provides information to the recognizer
that specifies how to process the request.audio - [Required] The audio data to be recognized.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.longrunning.Operation asyncRecognize(com.google.cloud.speech.v1beta1.AsyncRecognizeRequest request)
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
AsyncRecognizeRequest request = AsyncRecognizeRequest.newBuilder()
.setConfig(config)
.setAudio(audio)
.build();
Operation response = speechApi.asyncRecognize(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.grpc.ApiException - if the remote call failspublic final com.google.api.gax.grpc.ApiCallable<com.google.cloud.speech.v1beta1.AsyncRecognizeRequest,com.google.longrunning.Operation> asyncRecognizeCallable()
try (SpeechApi speechApi = SpeechApi.create()) {
RecognitionConfig config = RecognitionConfig.newBuilder().build();
RecognitionAudio audio = RecognitionAudio.newBuilder().build();
AsyncRecognizeRequest request = AsyncRecognizeRequest.newBuilder()
.setConfig(config)
.setAudio(audio)
.build();
ListenableFuture<Operation> future = speechApi.asyncRecognizeCallable().futureCall(request);
// Do something
Operation response = future.get();
}
public final void close()
throws Exception
close in interface AutoCloseableExceptionCopyright © 2016 Google. All rights reserved.