Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Commit

Permalink
Replace manual Speech library with GAPIC and helpers (googleapis#1977)
Browse files Browse the repository at this point in the history
This PR replaces the existing Speech client library with an auto-generated
library. The auto-generated code is supplemented with a helper that wraps the
auto-generated bidi streaming RPC in the stream class from the old manual
library.

(Note that this is a divergence from the Python library, but one that should
substantially improve the usability of bidi streaming relative to Python.)

As such, it substantially changes the public surface.
  • Loading branch information
geigerj authored and blowmage committed Jun 13, 2018
1 parent c258bb3 commit 9cc2064
Show file tree
Hide file tree
Showing 56 changed files with 1,163 additions and 5,216 deletions.
15 changes: 0 additions & 15 deletions google-cloud-speech/.autotest

This file was deleted.

4 changes: 4 additions & 0 deletions google-cloud-speech/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ jsondoc/*

# Ignore YARD stuffs
.yardoc

# IDE settings
.idea
*.iml
30 changes: 9 additions & 21 deletions google-cloud-speech/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ AllCops:
Exclude:
- "acceptance/**/*"
- "google-cloud-speech.gemspec"
- "lib/google/cloud/speech.rb"
- "lib/google/cloud/speech/*"
- "lib/google/cloud/speech/v1/*pb.rb"
- "lib/google/cloud/speech/v1/speech_client.rb"
- "lib/google/cloud/speech/v1/doc/**/*"
- "Rakefile"
- "support/**/*"
- "test/**/*"
- "lib/google/cloud/speech/v1/**/*"
- "lib/google/cloud/speech/v1.rb"

- "test/google/cloud/speech/v1/**/*"

Documentation:
Enabled: false
Expand All @@ -16,22 +17,9 @@ Style/StringLiterals:
EnforcedStyle: double_quotes
Style/MethodDefParentheses:
EnforcedStyle: require_no_parentheses
Style/NumericLiterals:
Enabled: false
Metrics/CyclomaticComplexity:
Max: 10
Metrics/PerceivedComplexity:
Max: 10
Metrics/AbcSize:
Max: 25
Metrics/ClassLength:
Enabled: false
Metrics/MethodLength:
Max: 20
Metrics/ParameterLists:
Enabled: false
Layout/EmptyLines: # for the extra line between copyright and code
Enabled: false
Naming/FileName:
Metrics/BlockLength:
Exclude:
- "lib/google-cloud-speech.rb"
- "acceptance/**/*"
- "test/**/*"
3 changes: 2 additions & 1 deletion google-cloud-speech/.yardopts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--no-private
--title=Google Cloud Speech
--title=Google Cloud Speech API
--exclude _pb\.rb$
--markup markdown

./lib/**/*.rb
Expand Down
3 changes: 0 additions & 3 deletions google-cloud-speech/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ gemspec
gem "gcloud-jsondoc",
git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git",
branch: "gcloud-jsondoc"
gem "google-cloud-core", path: "../google-cloud-core"
gem "google-cloud-env", path: "../google-cloud-env"
gem "google-cloud-storage", path: "../google-cloud-storage"

if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1")
# WORKAROUND: builds are failing on Ruby 2.0.
Expand Down
2 changes: 1 addition & 1 deletion google-cloud-speech/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/

Expand Down
122 changes: 39 additions & 83 deletions google-cloud-speech/README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,49 @@
# google-cloud-speech
# Ruby Client for Google Cloud Speech API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))

[Google Cloud Speech API](https://cloud.google.com/speech/) ([docs](https://cloud.google.com/speech/docs)) enables developers to convert audio to text by applying powerful neural network models.

- [google-cloud-speech API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-speech/latest)
- [google-cloud-speech on RubyGems](https://rubygems.org/gems/google-cloud-speech)
- [Google Cloud Speech API documentation](https://cloud.google.com/speech/docs)
[Google Cloud Speech API][Product Documentation]:
Google Cloud Speech API.
- [Client Library Documentation][]
- [Product Documentation][]

## Quick Start
In order to use this library, you first need to go through the following
steps:

1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
3. [Enable the Google Cloud Speech API.](https://console.cloud.google.com/apis/api/speech)
4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)

```sh
### Installation
```
$ gem install google-cloud-speech
```

## Authentication

This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.

Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-speech/guides/authentication).

## Example

```ruby
### Preview
#### SpeechClient
```rb
require "google/cloud/speech"

speech = Google::Cloud::Speech.new

audio = speech.audio "path/to/audio.raw",
encoding: :linear16,
language: "en-US",
sample_rate: 16000

results = audio.recognize
result = results.first
result.transcript #=> "how old is the Brooklyn Bridge"
result.confidence #=> 0.9826789498329163
```

## Enabling Logging

To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below, or a [`Google::Cloud::Logging::Logger`](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger) that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb) and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.

Configuring a Ruby stdlib logger:

```ruby
require "logger"

module MyLogger
LOGGER = Logger.new $stderr, level: Logger::WARN
def logger
LOGGER
end
end

# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
module GRPC
extend MyLogger
end
speech_client = Google::Cloud::Speech.new
language_code = "en-US"
sample_rate_hertz = 44100
encoding = :FLAC
config = {
language_code: language_code,
sample_rate_hertz: sample_rate_hertz,
encoding: encoding
}
uri = "gs://gapic-toolkit/hello.flac"
audio = { uri: uri }
response = speech_client.recognize(config, audio)
```

## Supported Ruby Versions

This library is supported on Ruby 2.0+.

However, Ruby 2.3 or later is strongly recommended, as earlier releases have
reached or are nearing end-of-life. After June 1, 2018, Google will provide
official support only for Ruby versions that are considered current and
supported by Ruby Core (that is, Ruby versions that are either in normal
maintenance or in security maintenance).
See https://www.ruby-lang.org/en/downloads/branches/ for further details.

## Versioning

This library follows [Semantic Versioning](http://semver.org/).

It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.

## Contributing

Contributions to this library are always welcome and highly encouraged.

See the [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing) for more information on how to get started.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.

## License

This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).

## Support

Please [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com).
### Next Steps
- Read the [Client Library Documentation][] for Google Cloud Speech API
to see other available methods on the client.
- Read the [Google Cloud Speech API Product documentation][Product Documentation]
to learn more about the product and see How-to Guides.
- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
to see the full list of Cloud APIs that we cover.

[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-speech/latest/google/cloud/speech/v1
[Product Documentation]: https://cloud.google.com/speech
Loading

0 comments on commit 9cc2064

Please sign in to comment.