| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 92ebe4f commit ff54b24
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,8 @@ | |||
| 14 | 14 | # See the License for the specific language governing permissions and | |
| 15 | 15 | # limitations under the License. | |
| 16 | 16 | ||
| 17 | + set -e | ||
| 18 | + | ||
| 17 | 19 | GCLOUD_PROJECT=$(gcloud config list project --format="value(core.project)" 2>/dev/null) | |
| 18 | 20 | ||
| 19 | 21 | echo "Configuring project $GCLOUD_PROJECT for system tests." | |
@@ -44,7 +46,7 @@ echo "Creating pubsub resources." | |||
| 44 | 46 | gcloud alpha pubsub topics create gae-mvm-pubsub-topic | |
| 45 | 47 | ||
| 46 | 48 | echo "Creating speech resources." | |
| 47 | - gsutil cp speech/api/resources/audio.flac gs://$GCLOUD_PROJECT/speech/ | ||
| 49 | + gsutil cp speech/api-client/resources/audio.raw gs://$GCLOUD_PROJECT/speech/ | ||
| 48 | 50 | ||
| 49 | 51 | echo "To finish setup, follow this link to enable APIs." | |
| 50 | 52 | 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" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,7 +90,7 @@ def _gcs_uri(text): | |||
| 90 | 90 | parser = argparse.ArgumentParser() | |
| 91 | 91 | parser.add_argument('input_uri', type=_gcs_uri) | |
| 92 | 92 | parser.add_argument( | |
| 93 | - '--encoding', default='FLAC', choices=[ | ||
| 93 | + '--encoding', default='LINEAR16', choices=[ | ||
| 94 | 94 | 'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'], | |
| 95 | 95 | help='How the audio file is encoded. See {}#L67'.format(PROTO_URL)) | |
| 96 | 96 | parser.add_argument('--sample_rate', type=int, default=16000) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,8 +20,8 @@ | |||
| 20 | 20 | import time | |
| 21 | 21 | ||
| 22 | 22 | from google.cloud.credentials import get_credentials | |
| 23 | - from google.cloud.speech.v1beta1 import cloud_speech_pb2 | ||
| 24 | - from google.longrunning import operations_grpc_pb2 | ||
| 23 | + from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2 | ||
| 24 | + from google.longrunning import operations_pb2 | ||
| 25 | 25 | from grpc.beta import implementations | |
| 26 | 26 | ||
| 27 | 27 | # Keep the request alive for this many seconds | |
@@ -76,7 +76,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'): | |||
| 76 | 76 | print(operation) | |
| 77 | 77 | ||
| 78 | 78 | # Construct a long running operation endpoint. | |
| 79 | - service = operations_grpc_pb2.beta_create_Operations_stub(channel) | ||
| 79 | + service = operations_pb2.beta_create_Operations_stub(channel) | ||
| 80 | 80 | ||
| 81 | 81 | name = operation.name | |
| 82 | 82 | ||
@@ -85,9 +85,12 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'): | |||
| 85 | 85 | print('Waiting for server processing...') | |
| 86 | 86 | time.sleep(1) | |
| 87 | 87 | operation = service.GetOperation( | |
| 88 | - operations_grpc_pb2.GetOperationRequest(name=name), | ||
| 88 | + operations_pb2.GetOperationRequest(name=name), | ||
| 89 | 89 | DEADLINE_SECS) | |
| 90 | 90 | ||
| 91 | + if operation.error.message: | ||
| 92 | + print('\nOperation error:\n{}'.format(operation.error)) | ||
| 93 | + | ||
| 91 | 94 | if operation.done: | |
| 92 | 95 | break | |
| 93 | 96 | ||
@@ -112,7 +115,7 @@ def _gcs_uri(text): | |||
| 112 | 115 | parser = argparse.ArgumentParser() | |
| 113 | 116 | parser.add_argument('input_uri', type=_gcs_uri) | |
| 114 | 117 | parser.add_argument( | |
| 115 | - '--encoding', default='FLAC', choices=[ | ||
| 118 | + '--encoding', default='LINEAR16', choices=[ | ||
| 116 | 119 | 'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'], | |
| 117 | 120 | help='How the audio file is encoded. See {}#L67'.format( | |
| 118 | 121 | 'https://github.com/googleapis/googleapis/blob/master/' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + # Copyright 2016, Google, Inc. | ||
| 2 | + # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | + # you may not use this file except in compliance with the License. | ||
| 4 | + # You may obtain a copy of the License at | ||
| 5 | + # | ||
| 6 | + # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | + # | ||
| 8 | + # Unless required by applicable law or agreed to in writing, software | ||
| 9 | + # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | + # See the License for the specific language governing permissions and | ||
| 12 | + # limitations under the License. | ||
| 13 | + | ||
| 14 | + import re | ||
| 15 | + | ||
| 16 | + from transcribe_async import main | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + def test_main(resource, capsys, cloud_config): | ||
| 20 | + | ||
| 21 | + # Run the transcribe sample on audio.raw, verify correct results | ||
| 22 | + storage_uri = 'gs://{}/speech/audio.raw'.format( | ||
| 23 | + cloud_config.storage_bucket) | ||
| 24 | + main(storage_uri, 'LINEAR16', 16000) | ||
| 25 | + out, err = capsys.readouterr() | ||
| 26 | + assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,26 @@ | |||
| 1 | + # Copyright 2016, Google, Inc. | ||
| 2 | + # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | + # you may not use this file except in compliance with the License. | ||
| 4 | + # You may obtain a copy of the License at | ||
| 5 | + # | ||
| 6 | + # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | + # | ||
| 8 | + # Unless required by applicable law or agreed to in writing, software | ||
| 9 | + # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | + # See the License for the specific language governing permissions and | ||
| 12 | + # limitations under the License. | ||
| 13 | + | ||
| 14 | + import re | ||
| 15 | + | ||
| 16 | + from transcribe import main | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + def test_main(resource, capsys, cloud_config): | ||
| 20 | + | ||
| 21 | + # Run the transcribe sample on audio.raw, verify correct results | ||
| 22 | + storage_uri = 'gs://{}/speech/audio.raw'.format( | ||
| 23 | + cloud_config.storage_bucket) | ||
| 24 | + main(storage_uri, 'LINEAR16', 16000) | ||
| 25 | + out, err = capsys.readouterr() | ||
| 26 | + assert re.search(r'how old is the Brooklyn Bridge', out, re.DOTALL | re.I) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments