Skip to content

Commit 19e4c89

Browse files
committed
Feedback updates.
1 parent c30ea2f commit 19e4c89

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

system_tests/speech.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
1516
import unittest
1617

1718
from google.cloud import exceptions
1819
from google.cloud import speech
1920
from google.cloud import storage
21+
from google.cloud.speech.transcript import Transcript
2022

2123
from system_test_utils import unique_resource_id
2224
from retry import RetryErrors
2325

2426

2527
class Config(object):
2628
"""Run-time configuration to be modified at set-up.
29+
2730
This is a mutable stand-in to allow test set-up to modify
2831
global state.
2932
"""
3033
CLIENT = None
3134
TEST_BUCKET = None
35+
AUDIO_FILE = os.path.join(os.path.dirname(__file__), 'data', 'hello.wav')
36+
ASSERT_TEXT = 'thank you for using Google Cloud platform'
3237

3338

3439
def setUpModule():
@@ -69,48 +74,35 @@ def _make_sync_request(self, content=None, source_uri=None,
6974
language_code='en-US',
7075
max_alternatives=max_alternatives,
7176
profanity_filter=True,
72-
speech_context=['Google',
73-
'cloud'])
77+
speech_context=['Google', 'cloud'])
7478
return result
7579

7680
def _check_best_results(self, results):
77-
from google.cloud.speech.transcript import Transcript
78-
7981
top_result = results[0]
8082
self.assertIsInstance(top_result, Transcript)
8183
self.assertEqual(top_result.transcript,
82-
'hello thank you for using Google Cloud platform')
84+
'hello ' + Config.ASSERT_TEXT)
8385
self.assertGreater(top_result.confidence, 0.90)
8486

8587
def test_sync_recognize_local_file(self):
86-
import os
87-
from google.cloud.speech.transcript import Transcript
88-
89-
file_name = os.path.join('system_tests', 'data', 'hello.wav')
90-
91-
with open(file_name, 'rb') as file_obj:
88+
with open(Config.AUDIO_FILE, 'rb') as file_obj:
9289
results = self._make_sync_request(content=file_obj.read(),
9390
max_alternatives=2)
9491
second_alternative = results[1]
9592
self.assertEqual(len(results), 2)
9693
self._check_best_results(results)
9794
self.assertIsInstance(second_alternative, Transcript)
98-
self.assertEqual(second_alternative.transcript,
99-
'thank you for using Google Cloud platform')
95+
self.assertEqual(second_alternative.transcript, Config.ASSERT_TEXT)
10096
self.assertEqual(second_alternative.confidence, 0.0)
10197

10298
def test_sync_recognize_gcs_file(self):
103-
import os
104-
105-
file_name = os.path.join('system_tests', 'data', 'hello.wav')
10699
bucket_name = Config.TEST_BUCKET.name
107-
blob_name = 'document.txt'
100+
blob_name = 'hello.wav'
108101
blob = Config.TEST_BUCKET.blob(blob_name)
109102
self.to_delete_by_case.append(blob) # Clean-up.
110-
with open(file_name, 'rb') as file_obj:
103+
with open(Config.AUDIO_FILE, 'rb') as file_obj:
111104
blob.upload_from_file(file_obj)
112105

113-
# source_uri = os.getenv('SPEECH_GCS_URI')
114106
source_uri = 'gs://%s/%s' % (bucket_name, blob_name)
115107
result = self._make_sync_request(source_uri=source_uri,
116108
max_alternatives=1)

0 commit comments

Comments
 (0)