Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion gcloud-java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>0.0.14</version>
<version>0.0.15</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
Expand Down
126 changes: 126 additions & 0 deletions gcloud-java-speech/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0"?>
<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>gcloud-java-speech</artifactId>
<packaging>jar</packaging>
<name>GCloud Java Speech</name>
<url>https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-speech</url>
<description>
Java idiomatic client for Google Cloud Speech.
</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>gcloud-java-pom</artifactId>
<version>0.2.8-SNAPSHOT</version>
</parent>
<properties>
<site.installationModule>gcloud-java-speech</site.installationModule>
</properties>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>1.1.33.Fork17</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-speech-v1</artifactId>
<version>0.0.7</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>doclint-java8-disable</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<!-- add this to disable checking -->
<javadoc.opts>-Xdoclint:none</javadoc.opts>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>generated/src/main/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>${javadoc.opts}</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<!-- Downgrading to 3.1 because of https://issues.apache.org/jira/browse/MCOMPILER-236 -->
<!-- Upgrade to 3.5.1 which fixes the problem when available -->
<!-- <version>3.5.1</version> -->
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArgument>-Xlint:unchecked</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.cloud.speech.spi.v1;

import com.google.api.gax.grpc.ApiCallable;
import com.google.api.gax.protobuf.PathTemplate;
import com.google.cloud.speech.v1.AudioRequest;
import com.google.cloud.speech.v1.InitialRecognizeRequest;
import com.google.cloud.speech.v1.NonStreamingRecognizeResponse;
import com.google.cloud.speech.v1.RecognizeRequest;
import io.grpc.ManagedChannel;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

// AUTO-GENERATED DOCUMENTATION AND SERVICE
/**
* Service Description: Service that implements Google Cloud Speech API.
*
* <p>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:
*
* <pre>
* <code>
* try (SpeechApi speechApi = SpeechApi.create()) {
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
* NonStreamingRecognizeResponse response = speechApi.nonStreamingRecognize(initialRequest, audioRequest);
* }
* </code>
* </pre>
*
* <p>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().
*
* <p>The surface of this class includes several types of Java methods for each of the API's methods:
*
* <ol>
* <li> A "flattened" method. With this type of method, the fields of the request type have been
* converted into function parameters. It may be the case that not all fields are available
* as parameters, and not every API method will have a flattened method entry point.
* <li> A "request object" method. This type of method only takes one parameter, a request
* object, which must be constructed before the call. Not every API method will have a request
* object method.
* <li> A "callable" method. This type of method takes no parameters and returns an immutable
* ApiCallable object, which can be used to initiate calls to the service.
* </ol>
*
* <p>See the individual methods for example code.
*
* <p>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.
*
* <p>This class can be customized by passing in a custom instance of SpeechSettings to
* create(). For example:
*
* <pre>
* <code>
* SpeechSettings speechSettings = SpeechSettings.defaultBuilder()
* .provideChannelWith(myCredentials)
* .build();
* SpeechApi speechApi = SpeechApi.create(speechSettings);
* </code>
* </pre>
*/
@javax.annotation.Generated("by GAPIC")
public class SpeechApi implements AutoCloseable {
private final SpeechSettings settings;
private final ManagedChannel channel;
private final ScheduledExecutorService executor;
private final List<AutoCloseable> closeables = new ArrayList<>();

private final ApiCallable<RecognizeRequest, NonStreamingRecognizeResponse>
nonStreamingRecognizeCallable;

public final SpeechSettings getSettings() {
return settings;
}

/**
* Constructs an instance of SpeechApi with default settings.
*/
public static final SpeechApi create() throws IOException {
return create(SpeechSettings.defaultBuilder().build());
}

/**
* Constructs an instance of SpeechApi, using the given settings.
* The channels are created based on the settings passed in, or defaults for any
* settings that are not set.
*/
public static final SpeechApi create(SpeechSettings settings) throws IOException {
return new SpeechApi(settings);
}

/**
* Constructs an instance of SpeechApi, using the given settings.
* This is protected so that it easy to make a subclass, but otherwise, the static
* factory methods should be preferred.
*/
protected SpeechApi(SpeechSettings settings) throws IOException {
this.settings = settings;
this.executor = settings.getExecutorProvider().getOrBuildExecutor();
this.channel = settings.getChannelProvider().getOrBuildChannel(this.executor);

this.nonStreamingRecognizeCallable =
ApiCallable.create(settings.nonStreamingRecognizeSettings(), this.channel, this.executor);

if (settings.getChannelProvider().shouldAutoClose()) {
closeables.add(
new Closeable() {
@Override
public void close() throws IOException {
channel.shutdown();
}
});
}
if (settings.getExecutorProvider().shouldAutoClose()) {
closeables.add(
new Closeable() {
@Override
public void close() throws IOException {
executor.shutdown();
}
});
}
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Perform non-streaming speech-recognition: receive results after all audio
* has been sent and processed.
*
* Sample code:
* <pre><code>
* try (SpeechApi speechApi = SpeechApi.create()) {
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
* NonStreamingRecognizeResponse response = speechApi.nonStreamingRecognize(initialRequest, audioRequest);
* }
* </code></pre>
*
* @param initialRequest The `initial_request` message provides information to the recognizer
* that specifies how to process the request.
*
* The first `RecognizeRequest` message must contain an `initial_request`.
* Any subsequent `RecognizeRequest` messages must not contain an
* `initial_request`.
* @param audioRequest The audio data to be recognized. For REST or `NonStreamingRecognize`, all
* audio data must be contained in the first (and only) `RecognizeRequest`
* message. For gRPC streaming `Recognize`, sequential chunks of audio data
* are sent in sequential `RecognizeRequest` messages.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final NonStreamingRecognizeResponse nonStreamingRecognize(
InitialRecognizeRequest initialRequest, AudioRequest audioRequest) {
RecognizeRequest request =
RecognizeRequest.newBuilder()
.setInitialRequest(initialRequest)
.setAudioRequest(audioRequest)
.build();
return nonStreamingRecognize(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Perform non-streaming speech-recognition: receive results after all audio
* has been sent and processed.
*
* Sample code:
* <pre><code>
* try (SpeechApi speechApi = SpeechApi.create()) {
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
* RecognizeRequest request = RecognizeRequest.newBuilder()
* .setInitialRequest(initialRequest)
* .setAudioRequest(audioRequest)
* .build();
* NonStreamingRecognizeResponse response = speechApi.nonStreamingRecognize(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final NonStreamingRecognizeResponse nonStreamingRecognize(RecognizeRequest request) {
return nonStreamingRecognizeCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Perform non-streaming speech-recognition: receive results after all audio
* has been sent and processed.
*
* Sample code:
* <pre><code>
* try (SpeechApi speechApi = SpeechApi.create()) {
* InitialRecognizeRequest initialRequest = InitialRecognizeRequest.newBuilder().build();
* AudioRequest audioRequest = AudioRequest.newBuilder().build();
* RecognizeRequest request = RecognizeRequest.newBuilder()
* .setInitialRequest(initialRequest)
* .setAudioRequest(audioRequest)
* .build();
* ListenableFuture&lt;NonStreamingRecognizeResponse&gt; future = speechApi.nonStreamingRecognizeCallable().futureCall(request);
* // Do something
* NonStreamingRecognizeResponse response = future.get();
* }
* </code></pre>
*/
public final ApiCallable<RecognizeRequest, NonStreamingRecognizeResponse>
nonStreamingRecognizeCallable() {
return nonStreamingRecognizeCallable;
}

/**
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
* cancelled.
*/
@Override
public final void close() throws Exception {
for (AutoCloseable closeable : closeables) {
closeable.close();
}
}
}
Loading