diff --git a/speech/api-client/README.rst b/speech/api-client/README.rst deleted file mode 100644 index 45e74ac3dc5..00000000000 --- a/speech/api-client/README.rst +++ /dev/null @@ -1,115 +0,0 @@ -.. This file is automatically generated. Do not edit this file directly. - -Google Cloud Speech API Python Samples -=============================================================================== - -This directory contains samples for Google Cloud Speech API. `Google Cloud Speech API`_ enables easy integration of Google speech recognition technologies into developer applications. Send audio and receive a text transcription from the Cloud Speech API service. - - - - -.. _Google Cloud Speech API: https://cloud.google.com/speech/docs - -Setup -------------------------------------------------------------------------------- - - -Authentication -++++++++++++++ - -Authentication is typically done through `Application Default Credentials`_, -which means you do not have to change the code to authenticate as long as -your environment has credentials. You have a few options for setting up -authentication: - -#. When running locally, use the `Google Cloud SDK`_ - - .. code-block:: bash - - gcloud beta auth application-default login - - -#. When running on App Engine or Compute Engine, credentials are already - set-up. However, you may need to configure your Compute Engine instance - with `additional scopes`_. - -#. You can create a `Service Account key file`_. This file can be used to - authenticate to Google Cloud Platform services from any environment. To use - the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to - the path to the key file, for example: - - .. code-block:: bash - - export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json - -.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow -.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using -.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount - -Install Dependencies -++++++++++++++++++++ - -#. Install `pip`_ and `virtualenv`_ if you do not already have them. - -#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. - - .. code-block:: bash - - $ virtualenv env - $ source env/bin/activate - -#. Install the dependencies needed to run the samples. - - .. code-block:: bash - - $ pip install -r requirements.txt - -.. _pip: https://pip.pypa.io/ -.. _virtualenv: https://virtualenv.pypa.io/ - -Samples -------------------------------------------------------------------------------- - -Transcribe -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - - -To run this sample: - -.. code-block:: bash - - $ python transcribe.py - - usage: transcribe.py [-h] speech_file - - positional arguments: - speech_file Full path of audio file to be recognized - - optional arguments: - -h, --help show this help message and exit - - -Transcribe async -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - - -To run this sample: - -.. code-block:: bash - - $ python transcribe_async.py - - usage: transcribe_async.py [-h] speech_file - - positional arguments: - speech_file Full path of audio file to be recognized - - optional arguments: - -h, --help show this help message and exit - - - - -.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/speech/api-client/README.rst.in b/speech/api-client/README.rst.in deleted file mode 100644 index 667b30debe0..00000000000 --- a/speech/api-client/README.rst.in +++ /dev/null @@ -1,22 +0,0 @@ -# This file is used to generate README.rst - -product: - name: Google Cloud Speech API - short_name: Cloud Speech API - url: https://cloud.google.com/speech/docs - description: > - `Google Cloud Speech API`_ enables easy integration of Google speech - recognition technologies into developer applications. Send audio and - receive a text transcription from the Cloud Speech API service. - -setup: -- auth -- install_deps - -samples: -- name: Transcribe - file: transcribe.py - show_help: true -- name: Transcribe async - file: transcribe_async.py - show_help: true diff --git a/speech/api-client/requirements.txt b/speech/api-client/requirements.txt deleted file mode 100644 index ce6a9bf5bad..00000000000 --- a/speech/api-client/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -google-api-python-client==1.6.1 diff --git a/speech/api-client/resources/audio.raw b/speech/api-client/resources/audio.raw deleted file mode 100644 index 5ebf79d3c9c..00000000000 Binary files a/speech/api-client/resources/audio.raw and /dev/null differ diff --git a/speech/api-client/resources/audio2.raw b/speech/api-client/resources/audio2.raw deleted file mode 100644 index 35413b78817..00000000000 Binary files a/speech/api-client/resources/audio2.raw and /dev/null differ diff --git a/speech/api-client/transcribe.py b/speech/api-client/transcribe.py deleted file mode 100644 index b5ad7e215d1..00000000000 --- a/speech/api-client/transcribe.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# 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. -"""Google Cloud Speech API sample application using the REST API for batch -processing.""" - -# [START import_libraries] -import argparse -import base64 -import json - -from googleapiclient import discovery -import httplib2 -from oauth2client.client import GoogleCredentials -# [END import_libraries] - - -# [START authenticating] -DISCOVERY_URL = ('https://{api}.googleapis.com/$discovery/rest?' - 'version={apiVersion}') - - -# Application default credentials provided by env variable -# GOOGLE_APPLICATION_CREDENTIALS -def get_speech_service(): - credentials = GoogleCredentials.get_application_default().create_scoped( - ['https://www.googleapis.com/auth/cloud-platform']) - http = httplib2.Http() - credentials.authorize(http) - - return discovery.build( - 'speech', 'v1beta1', http=http, discoveryServiceUrl=DISCOVERY_URL) -# [END authenticating] - - -def main(speech_file): - """Transcribe the given audio file. - - Args: - speech_file: the name of the audio file. - """ - # [START construct_request] - with open(speech_file, 'rb') as speech: - # Base64 encode the binary audio file for inclusion in the JSON - # request. - speech_content = base64.b64encode(speech.read()) - - service = get_speech_service() - service_request = service.speech().syncrecognize( - body={ - 'config': { - # There are a bunch of config options you can specify. See - # https://goo.gl/KPZn97 for the full list. - 'encoding': 'LINEAR16', # raw 16-bit signed LE samples - 'sampleRate': 16000, # 16 khz - # See http://g.co/cloud/speech/docs/languages for a list of - # supported languages. - 'languageCode': 'en-US', # a BCP-47 language tag - }, - 'audio': { - 'content': speech_content.decode('UTF-8') - } - }) - # [END construct_request] - # [START send_request] - response = service_request.execute() - - # First print the raw json response - print(json.dumps(response, indent=2)) - - # Now print the actual transcriptions - for result in response.get('results', []): - print('Result:') - for alternative in result['alternatives']: - print(u' Alternative: {}'.format(alternative['transcript'])) - # [END send_request] - - -# [START run_application] -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument( - 'speech_file', help='Full path of audio file to be recognized') - args = parser.parse_args() - main(args.speech_file) - # [END run_application] diff --git a/speech/api-client/transcribe_async.py b/speech/api-client/transcribe_async.py deleted file mode 100644 index 27a0ef7bf8f..00000000000 --- a/speech/api-client/transcribe_async.py +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env python -# 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. -"""Google Cloud Speech API sample application using the REST API for async -batch processing.""" - -# [START import_libraries] -import argparse -import base64 -import json -import time - -from googleapiclient import discovery -import httplib2 -from oauth2client.client import GoogleCredentials -# [END import_libraries] - - -# [START authenticating] - - -# Application default credentials provided by env variable -# GOOGLE_APPLICATION_CREDENTIALS -def get_speech_service(): - credentials = GoogleCredentials.get_application_default().create_scoped( - ['https://www.googleapis.com/auth/cloud-platform']) - http = httplib2.Http() - credentials.authorize(http) - - return discovery.build('speech', 'v1beta1', http=http) -# [END authenticating] - - -def main(speech_file): - """Transcribe the given audio file asynchronously. - - Args: - speech_file: the name of the audio file. - """ - # [START construct_request] - with open(speech_file, 'rb') as speech: - # Base64 encode the binary audio file for inclusion in the request. - speech_content = base64.b64encode(speech.read()) - - service = get_speech_service() - service_request = service.speech().asyncrecognize( - body={ - 'config': { - # There are a bunch of config options you can specify. See - # https://goo.gl/KPZn97 for the full list. - 'encoding': 'LINEAR16', # raw 16-bit signed LE samples - 'sampleRate': 16000, # 16 khz - # See http://g.co/cloud/speech/docs/languages for a list of - # supported languages. - 'languageCode': 'en-US', # a BCP-47 language tag - }, - 'audio': { - 'content': speech_content.decode('UTF-8') - } - }) - # [END construct_request] - # [START send_request] - response = service_request.execute() - print(json.dumps(response)) - # [END send_request] - - name = response['name'] - # Construct a GetOperation request. - service_request = service.operations().get(name=name) - - while True: - # Give the server a few seconds to process. - print('Waiting for server processing...') - time.sleep(1) - # Get the long running operation with response. - response = service_request.execute() - - if 'done' in response and response['done']: - break - - # First print the raw json response - print(json.dumps(response['response'], indent=2)) - - # Now print the actual transcriptions - for result in response['response'].get('results', []): - print('Result:') - for alternative in result['alternatives']: - print(u' Alternative: {}'.format(alternative['transcript'])) - - -# [START run_application] -if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument( - 'speech_file', help='Full path of audio file to be recognized') - args = parser.parse_args() - main(args.speech_file) - # [END run_application] diff --git a/speech/api-client/transcribe_async_test.py b/speech/api-client/transcribe_async_test.py deleted file mode 100644 index d90f45608c8..00000000000 --- a/speech/api-client/transcribe_async_test.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2016, Google, Inc. -# 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. - -import re - -from transcribe_async import main - - -def test_main(resource, capsys): - main(resource('audio.raw')) - out, err = capsys.readouterr() - - assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) diff --git a/speech/api-client/transcribe_test.py b/speech/api-client/transcribe_test.py deleted file mode 100644 index c8cb0a70333..00000000000 --- a/speech/api-client/transcribe_test.py +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2016, Google, Inc. -# 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. - -import re - -from transcribe import main - - -def test_main(resource, capsys): - main(resource('audio.raw')) - out, err = capsys.readouterr() - - assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)