Skip to content

Commit ff54b24

Browse files
ryanmatsJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Speech transcribe async bug (#688)
1 parent 92ebe4f commit ff54b24

File tree

6 files changed

+64
-7
lines changed

6 files changed

+64
-7
lines changed

scripts/prepare-testing-project.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17+
set -e
18+
1719
GCLOUD_PROJECT=$(gcloud config list project --format="value(core.project)" 2>/dev/null)
1820

1921
echo "Configuring project $GCLOUD_PROJECT for system tests."
@@ -44,7 +46,7 @@ echo "Creating pubsub resources."
4446
gcloud alpha pubsub topics create gae-mvm-pubsub-topic
4547

4648
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/
4850

4951
echo "To finish setup, follow this link to enable APIs."
5052
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"

speech/grpc/resources/audio.raw

56.6 KB
Binary file not shown.

speech/grpc/transcribe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def _gcs_uri(text):
9090
parser = argparse.ArgumentParser()
9191
parser.add_argument('input_uri', type=_gcs_uri)
9292
parser.add_argument(
93-
'--encoding', default='FLAC', choices=[
93+
'--encoding', default='LINEAR16', choices=[
9494
'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'],
9595
help='How the audio file is encoded. See {}#L67'.format(PROTO_URL))
9696
parser.add_argument('--sample_rate', type=int, default=16000)

speech/grpc/transcribe_async.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import time
2121

2222
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
2525
from grpc.beta import implementations
2626

2727
# Keep the request alive for this many seconds
@@ -76,7 +76,7 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
7676
print(operation)
7777

7878
# 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)
8080

8181
name = operation.name
8282

@@ -85,9 +85,12 @@ def main(input_uri, encoding, sample_rate, language_code='en-US'):
8585
print('Waiting for server processing...')
8686
time.sleep(1)
8787
operation = service.GetOperation(
88-
operations_grpc_pb2.GetOperationRequest(name=name),
88+
operations_pb2.GetOperationRequest(name=name),
8989
DEADLINE_SECS)
9090

91+
if operation.error.message:
92+
print('\nOperation error:\n{}'.format(operation.error))
93+
9194
if operation.done:
9295
break
9396

@@ -112,7 +115,7 @@ def _gcs_uri(text):
112115
parser = argparse.ArgumentParser()
113116
parser.add_argument('input_uri', type=_gcs_uri)
114117
parser.add_argument(
115-
'--encoding', default='FLAC', choices=[
118+
'--encoding', default='LINEAR16', choices=[
116119
'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'],
117120
help='How the audio file is encoded. See {}#L67'.format(
118121
'https://github.com/googleapis/googleapis/blob/master/'

speech/grpc/transcribe_async_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

speech/grpc/transcribe_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)