diff --git a/speech/cloud-client/README.rst.in b/speech/cloud-client/README.rst.in new file mode 100644 index 000000000000..fbeb326e6eb9 --- /dev/null +++ b/speech/cloud-client/README.rst.in @@ -0,0 +1,20 @@ +# 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: > + The `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: Quickstart + file: quickstart.py + +cloud_client_library: true diff --git a/speech/cloud-client/quickstart.py b/speech/cloud-client/quickstart.py new file mode 100644 index 000000000000..7a0a798cd280 --- /dev/null +++ b/speech/cloud-client/quickstart.py @@ -0,0 +1,53 @@ +#!/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. + + +def run_quickstart(): + # [START speech_quickstart] + import io + import os + + # Imports the Google Cloud client library + from google.cloud import speech + + # Instantiates a client + speech_client = speech.Client() + + # The name of the audio file to transcribe + file_name = os.path.join( + os.path.dirname(__file__), + 'resources', + 'audio.raw') + + # Loads the audio into memory + with io.open(file_name, 'rb') as audio_file: + content = audio_file.read() + audio_sample = speech_client.sample( + content, + source_uri=None, + encoding='LINEAR16', + sample_rate=16000) + + # Detects speech in the audio file + alternatives = speech_client.speech_api.sync_recognize(audio_sample) + + for alternative in alternatives: + print('Transcript: {}'.format(alternative.transcript)) + # [END speech_quickstart] + + +if __name__ == '__main__': + run_quickstart() diff --git a/speech/cloud-client/quickstart_test.py b/speech/cloud-client/quickstart_test.py new file mode 100644 index 000000000000..0675ad195d3a --- /dev/null +++ b/speech/cloud-client/quickstart_test.py @@ -0,0 +1,22 @@ +# 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. + + +import quickstart + + +def test_quickstart(capsys): + quickstart.run_quickstart() + out, _ = capsys.readouterr() + assert 'Transcript: how old is the Brooklyn Bridge' in out diff --git a/speech/cloud-client/requirements.txt b/speech/cloud-client/requirements.txt new file mode 100644 index 000000000000..f14b18d371ef --- /dev/null +++ b/speech/cloud-client/requirements.txt @@ -0,0 +1 @@ +google-cloud-speech==0.21.0 diff --git a/speech/cloud-client/resources/audio.raw b/speech/cloud-client/resources/audio.raw new file mode 100644 index 000000000000..5ebf79d3c9c5 Binary files /dev/null and b/speech/cloud-client/resources/audio.raw differ