Skip to content

Commit 822e139

Browse files
Initial auto-generated gcloud-java-speech
1 parent 7c4678d commit 822e139

9 files changed

Lines changed: 912 additions & 1 deletion

File tree

gcloud-java-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<dependency>
107107
<groupId>com.google.api</groupId>
108108
<artifactId>gax</artifactId>
109-
<version>0.0.14</version>
109+
<version>0.0.15</version>
110110
</dependency>
111111
<dependency>
112112
<groupId>com.google.api.grpc</groupId>

gcloud-java-speech/pom.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>gcloud-java-speech</artifactId>
5+
<packaging>jar</packaging>
6+
<name>GCloud Java Speech</name>
7+
<url>https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-speech</url>
8+
<description>
9+
Java idiomatic client for Google Cloud Speech.
10+
</description>
11+
<parent>
12+
<groupId>com.google.cloud</groupId>
13+
<artifactId>gcloud-java-pom</artifactId>
14+
<version>0.2.8-SNAPSHOT</version>
15+
</parent>
16+
<properties>
17+
<site.installationModule>gcloud-java-speech</site.installationModule>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>io.netty</groupId>
22+
<artifactId>netty-tcnative-boringssl-static</artifactId>
23+
<version>1.1.33.Fork17</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>${project.groupId}</groupId>
27+
<artifactId>gcloud-java-core</artifactId>
28+
<version>${project.version}</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.google.api.grpc</groupId>
32+
<artifactId>grpc-google-cloud-speech-v1</artifactId>
33+
<version>0.0.7</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>io.grpc</groupId>
37+
<artifactId>grpc-all</artifactId>
38+
<version>0.15.0</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.google.auto.value</groupId>
42+
<artifactId>auto-value</artifactId>
43+
<version>1.1</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>${project.groupId}</groupId>
47+
<artifactId>gcloud-java-core</artifactId>
48+
<version>${project.version}</version>
49+
<type>test-jar</type>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>junit</groupId>
54+
<artifactId>junit</artifactId>
55+
<version>4.12</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.easymock</groupId>
60+
<artifactId>easymock</artifactId>
61+
<version>3.4</version>
62+
<scope>test</scope>
63+
</dependency>
64+
</dependencies>
65+
<profiles>
66+
<profile>
67+
<id>doclint-java8-disable</id>
68+
<activation>
69+
<jdk>[1.8,)</jdk>
70+
</activation>
71+
<properties>
72+
<!-- add this to disable checking -->
73+
<javadoc.opts>-Xdoclint:none</javadoc.opts>
74+
</properties>
75+
</profile>
76+
</profiles>
77+
<build>
78+
<plugins>
79+
<plugin>
80+
<groupId>org.codehaus.mojo</groupId>
81+
<artifactId>build-helper-maven-plugin</artifactId>
82+
<version>1.9.1</version>
83+
<executions>
84+
<execution>
85+
<phase>generate-sources</phase>
86+
<goals><goal>add-source</goal></goals>
87+
<configuration>
88+
<sources>
89+
<source>generated/src/main/java</source>
90+
</sources>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-javadoc-plugin</artifactId>
98+
<version>2.10.3</version>
99+
<executions>
100+
<execution>
101+
<id>attach-javadocs</id>
102+
<goals>
103+
<goal>jar</goal>
104+
</goals>
105+
<configuration>
106+
<additionalparam>${javadoc.opts}</additionalparam>
107+
</configuration>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
<plugin>
112+
<artifactId>maven-compiler-plugin</artifactId>
113+
<!-- Downgrading to 3.1 because of https://issues.apache.org/jira/browse/MCOMPILER-236 -->
114+
<!-- Upgrade to 3.5.1 which fixes the problem when available -->
115+
<!-- <version>3.5.1</version> -->
116+
<version>3.1</version>
117+
<configuration>
118+
<source>1.7</source>
119+
<target>1.7</target>
120+
<encoding>UTF-8</encoding>
121+
<compilerArgument>-Xlint:unchecked</compilerArgument>
122+
</configuration>
123+
</plugin>
124+
</plugins>
125+
</build>
126+
</project>
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package com.google.cloud.speech.spi.v1;
15+
16+
import com.google.api.gax.grpc.ApiCallable;
17+
import com.google.api.gax.protobuf.PathTemplate;
18+
import com.google.cloud.speech.v1.AudioRequest;
19+
import com.google.cloud.speech.v1.InitialRecognizeRequest;
20+
import com.google.cloud.speech.v1.NonStreamingRecognizeResponse;
21+
import com.google.cloud.speech.v1.RecognizeRequest;
22+
import io.grpc.ManagedChannel;
23+
import java.io.Closeable;
24+
import java.io.IOException;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.concurrent.ScheduledExecutorService;
28+
29+
// AUTO-GENERATED DOCUMENTATION AND SERVICE
30+
/**
31+
* Service Description: Service that implements Google Cloud Speech API.
32+
*
33+
* <p>This class provides the ability to make remote calls to the backing service through method
34+
* calls that map to API methods. Sample code to get started:
35+
*
36+
* <pre>
37+
* <code>
38+
* try (SpeechApi speechApi = SpeechApi.create()) {
39+
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
40+
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
41+
* NonStreamingRecognizeResponse response = speechApi.nonStreamingRecognize(initialRequest, audioRequest);
42+
* }
43+
* </code>
44+
* </pre>
45+
*
46+
* <p>Note: close() needs to be called on the speechApi object to clean up resources such
47+
* as threads. In the example above, try-with-resources is used, which automatically calls
48+
* close().
49+
*
50+
* <p>The surface of this class includes several types of Java methods for each of the API's methods:
51+
*
52+
* <ol>
53+
* <li> A "flattened" method. With this type of method, the fields of the request type have been
54+
* converted into function parameters. It may be the case that not all fields are available
55+
* as parameters, and not every API method will have a flattened method entry point.
56+
* <li> A "request object" method. This type of method only takes one parameter, a request
57+
* object, which must be constructed before the call. Not every API method will have a request
58+
* object method.
59+
* <li> A "callable" method. This type of method takes no parameters and returns an immutable
60+
* ApiCallable object, which can be used to initiate calls to the service.
61+
* </ol>
62+
*
63+
* <p>See the individual methods for example code.
64+
*
65+
* <p>Many parameters require resource names to be formatted in a particular way. To assist
66+
* with these names, this class includes a format method for each type of name, and additionally
67+
* a parse method to extract the individual identifiers contained within names that are
68+
* returned.
69+
*
70+
* <p>This class can be customized by passing in a custom instance of SpeechSettings to
71+
* create(). For example:
72+
*
73+
* <pre>
74+
* <code>
75+
* SpeechSettings speechSettings = SpeechSettings.defaultBuilder()
76+
* .provideChannelWith(myCredentials)
77+
* .build();
78+
* SpeechApi speechApi = SpeechApi.create(speechSettings);
79+
* </code>
80+
* </pre>
81+
*/
82+
@javax.annotation.Generated("by GAPIC")
83+
public class SpeechApi implements AutoCloseable {
84+
private final SpeechSettings settings;
85+
private final ManagedChannel channel;
86+
private final ScheduledExecutorService executor;
87+
private final List<AutoCloseable> closeables = new ArrayList<>();
88+
89+
private final ApiCallable<RecognizeRequest, NonStreamingRecognizeResponse>
90+
nonStreamingRecognizeCallable;
91+
92+
public final SpeechSettings getSettings() {
93+
return settings;
94+
}
95+
96+
/**
97+
* Constructs an instance of SpeechApi with default settings.
98+
*/
99+
public static final SpeechApi create() throws IOException {
100+
return create(SpeechSettings.defaultBuilder().build());
101+
}
102+
103+
/**
104+
* Constructs an instance of SpeechApi, using the given settings.
105+
* The channels are created based on the settings passed in, or defaults for any
106+
* settings that are not set.
107+
*/
108+
public static final SpeechApi create(SpeechSettings settings) throws IOException {
109+
return new SpeechApi(settings);
110+
}
111+
112+
/**
113+
* Constructs an instance of SpeechApi, using the given settings.
114+
* This is protected so that it easy to make a subclass, but otherwise, the static
115+
* factory methods should be preferred.
116+
*/
117+
protected SpeechApi(SpeechSettings settings) throws IOException {
118+
this.settings = settings;
119+
this.executor = settings.getExecutorProvider().getOrBuildExecutor();
120+
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);
121+
122+
this.nonStreamingRecognizeCallable =
123+
ApiCallable.create(settings.nonStreamingRecognizeSettings(), this.channel, this.executor);
124+
125+
if (settings.getChannelProvider().shouldAutoClose()) {
126+
closeables.add(
127+
new Closeable() {
128+
@Override
129+
public void close() throws IOException {
130+
channel.shutdown();
131+
}
132+
});
133+
}
134+
if (settings.getExecutorProvider().shouldAutoClose()) {
135+
closeables.add(
136+
new Closeable() {
137+
@Override
138+
public void close() throws IOException {
139+
executor.shutdown();
140+
}
141+
});
142+
}
143+
}
144+
145+
// AUTO-GENERATED DOCUMENTATION AND METHOD
146+
/**
147+
* Perform non-streaming speech-recognition: receive results after all audio
148+
* has been sent and processed.
149+
*
150+
* Sample code:
151+
* <pre><code>
152+
* try (SpeechApi speechApi = SpeechApi.create()) {
153+
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
154+
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
155+
* NonStreamingRecognizeResponse response = speechApi.nonStreamingRecognize(initialRequest, audioRequest);
156+
* }
157+
* </code></pre>
158+
*
159+
* @param initialRequest The `initial_request` message provides information to the recognizer
160+
* that specifies how to process the request.
161+
*
162+
* The first `RecognizeRequest` message must contain an `initial_request`.
163+
* Any subsequent `RecognizeRequest` messages must not contain an
164+
* `initial_request`.
165+
* @param audioRequest The audio data to be recognized. For REST or `NonStreamingRecognize`, all
166+
* audio data must be contained in the first (and only) `RecognizeRequest`
167+
* message. For gRPC streaming `Recognize`, sequential chunks of audio data
168+
* are sent in sequential `RecognizeRequest` messages.
169+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
170+
*/
171+
public final NonStreamingRecognizeResponse nonStreamingRecognize(
172+
InitialRecognizeRequest initialRequest, AudioRequest audioRequest) {
173+
RecognizeRequest request =
174+
RecognizeRequest.newBuilder()
175+
.setInitialRequest(initialRequest)
176+
.setAudioRequest(audioRequest)
177+
.build();
178+
return nonStreamingRecognize(request);
179+
}
180+
181+
// AUTO-GENERATED DOCUMENTATION AND METHOD
182+
/**
183+
* Perform non-streaming speech-recognition: receive results after all audio
184+
* has been sent and processed.
185+
*
186+
* Sample code:
187+
* <pre><code>
188+
* try (SpeechApi speechApi = SpeechApi.create()) {
189+
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
190+
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
191+
* RecognizeRequest request = RecognizeRequest.newBuilder()
192+
* .setInitialRequest(initialRequest)
193+
* .setAudioRequest(audioRequest)
194+
* .build();
195+
* NonStreamingRecognizeResponse response = speechApi.nonStreamingRecognize(request);
196+
* }
197+
* </code></pre>
198+
*
199+
* @param request The request object containing all of the parameters for the API call.
200+
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
201+
*/
202+
public final NonStreamingRecognizeResponse nonStreamingRecognize(RecognizeRequest request) {
203+
return nonStreamingRecognizeCallable().call(request);
204+
}
205+
206+
// AUTO-GENERATED DOCUMENTATION AND METHOD
207+
/**
208+
* Perform non-streaming speech-recognition: receive results after all audio
209+
* has been sent and processed.
210+
*
211+
* Sample code:
212+
* <pre><code>
213+
* try (SpeechApi speechApi = SpeechApi.create()) {
214+
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
215+
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
216+
* RecognizeRequest request = RecognizeRequest.newBuilder()
217+
* .setInitialRequest(initialRequest)
218+
* .setAudioRequest(audioRequest)
219+
* .build();
220+
* ListenableFuture&lt;NonStreamingRecognizeResponse&gt; future = speechApi.nonStreamingRecognizeCallable().futureCall(request);
221+
* // Do something
222+
* NonStreamingRecognizeResponse response = future.get();
223+
* }
224+
* </code></pre>
225+
*/
226+
public final ApiCallable<RecognizeRequest, NonStreamingRecognizeResponse>
227+
nonStreamingRecognizeCallable() {
228+
return nonStreamingRecognizeCallable;
229+
}
230+
231+
/**
232+
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
233+
* cancelled.
234+
*/
235+
@Override
236+
public final void close() throws Exception {
237+
for (AutoCloseable closeable : closeables) {
238+
closeable.close();
239+
}
240+
}
241+
}

0 commit comments

Comments
 (0)