Skip to content
Merged
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
4 changes: 3 additions & 1 deletion scripts/prepare-testing-project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other tests that depend on audio.flac?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just searched through the repo and it doesn't look like there are. Also, the audio.flac file doesn't exist in that directory anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to set -e on the top of this file, so that the build will fail in the future when this happens..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(doesn't have to be in this CL - just saying it'd probably be a good idea..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed in this PR


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"
Binary file added speech/grpc/resources/audio.raw
Binary file not shown.
2 changes: 1 addition & 1 deletion speech/grpc/transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions speech/grpc/transcribe_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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/'
Expand Down
26 changes: 26 additions & 0 deletions speech/grpc/transcribe_async_test.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions speech/grpc/transcribe_test.py
Original file line number Diff line number Diff line change
@@ -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)