diff --git a/scripts/prepare-testing-project.sh b/scripts/prepare-testing-project.sh index c812b201ae0..f126723d634 100755 --- a/scripts/prepare-testing-project.sh +++ b/scripts/prepare-testing-project.sh @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +set -e + GCLOUD_PROJECT=$(gcloud config list project --format="value(core.project)" 2>/dev/null) echo "Configuring project $GCLOUD_PROJECT for system tests." @@ -44,7 +46,7 @@ echo "Creating pubsub resources." gcloud alpha pubsub topics create gae-mvm-pubsub-topic echo "Creating speech resources." -gsutil cp speech/api/resources/audio.flac gs://$GCLOUD_PROJECT/speech/ +gsutil cp speech/api-client/resources/audio.raw gs://$GCLOUD_PROJECT/speech/ echo "To finish setup, follow this link to enable APIs." echo "https://console.cloud.google.com/flows/enableapi?project=${GCLOUD_PROJECT}&apiid=bigtable.googleapis.com,bigtableadmin.googleapis.com,bigquery,cloudmonitoring,compute_component,datastore,datastore.googleapis.com,dataproc,dns,plus,pubsub,logging,storage_api,vision.googleapis.com" diff --git a/speech/grpc/resources/audio.raw b/speech/grpc/resources/audio.raw new file mode 100644 index 00000000000..5ebf79d3c9c Binary files /dev/null and b/speech/grpc/resources/audio.raw differ diff --git a/speech/grpc/transcribe.py b/speech/grpc/transcribe.py index 6505d011aee..b8527bc1f51 100644 --- a/speech/grpc/transcribe.py +++ b/speech/grpc/transcribe.py @@ -90,7 +90,7 @@ def _gcs_uri(text): parser = argparse.ArgumentParser() parser.add_argument('input_uri', type=_gcs_uri) parser.add_argument( - '--encoding', default='FLAC', choices=[ + '--encoding', default='LINEAR16', choices=[ 'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'], help='How the audio file is encoded. See {}#L67'.format(PROTO_URL)) parser.add_argument('--sample_rate', type=int, default=16000) diff --git a/speech/grpc/transcribe_async.py b/speech/grpc/transcribe_async.py index e5bfc9729fe..5db43173b61 100644 --- a/speech/grpc/transcribe_async.py +++ b/speech/grpc/transcribe_async.py @@ -20,8 +20,8 @@ import time from google.cloud.credentials import get_credentials -from google.cloud.speech.v1beta1 import cloud_speech_pb2 -from google.longrunning import operations_grpc_pb2 +from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 +from google.longrunning import operations_pb2 from grpc.beta import implementations # Keep the request alive for this many seconds @@ -76,7 +76,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'): print(operation) # Construct a long running operation endpoint. - service = operations_grpc_pb2.beta_create_Operations_stub(channel) + service = operations_pb2.beta_create_Operations_stub(channel) name = operation.name @@ -85,9 +85,12 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'): print('Waiting for server processing...') time.sleep(1) operation = service.GetOperation( - operations_grpc_pb2.GetOperationRequest(name=name), + operations_pb2.GetOperationRequest(name=name), DEADLINE_SECS) + if operation.error.message: + print('\nOperation error:\n{}'.format(operation.error)) + if operation.done: break @@ -112,7 +115,7 @@ def _gcs_uri(text): parser = argparse.ArgumentParser() parser.add_argument('input_uri', type=_gcs_uri) parser.add_argument( - '--encoding', default='FLAC', choices=[ + '--encoding', default='LINEAR16', choices=[ 'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'], help='How the audio file is encoded. See {}#L67'.format( 'https://github.com/googleapis/googleapis/blob/master/' diff --git a/speech/grpc/transcribe_async_test.py b/speech/grpc/transcribe_async_test.py new file mode 100644 index 00000000000..c57be620217 --- /dev/null +++ b/speech/grpc/transcribe_async_test.py @@ -0,0 +1,26 @@ +# 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, cloud_config): + + # Run the transcribe sample on audio.raw, verify correct results + storage_uri = 'gs://{}/speech/audio.raw'.format( + cloud_config.storage_bucket) + main(storage_uri, 'LINEAR16', 16000) + out, err = capsys.readouterr() + assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) diff --git a/speech/grpc/transcribe_test.py b/speech/grpc/transcribe_test.py new file mode 100644 index 00000000000..23b97c27100 --- /dev/null +++ b/speech/grpc/transcribe_test.py @@ -0,0 +1,26 @@ +# 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, cloud_config): + + # Run the transcribe sample on audio.raw, verify correct results + storage_uri = 'gs://{}/speech/audio.raw'.format( + cloud_config.storage_bucket) + main(storage_uri, 'LINEAR16', 16000) + out, err = capsys.readouterr() + assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I)