Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Speech sync recognize system test. #2547

Merged
merged 5 commits into from
Oct 27, 2016
Merged
Changes from 1 commit
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
30 changes: 11 additions & 19 deletions system_tests/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import unittest

from google.cloud import exceptions
from google.cloud import speech
from google.cloud import storage
from google.cloud.speech.transcript import Transcript

from system_test_utils import unique_resource_id
from retry import RetryErrors


class Config(object):
"""Run-time configuration to be modified at set-up.

This is a mutable stand-in to allow test set-up to modify

This comment was marked as spam.

global state.
"""
CLIENT = None
TEST_BUCKET = None
AUDIO_FILE = os.path.join(os.path.dirname(__file__), 'data', 'hello.wav')

This comment was marked as spam.

ASSERT_TEXT = 'thank you for using Google Cloud platform'

This comment was marked as spam.



def setUpModule():
Expand Down Expand Up @@ -69,48 +74,35 @@ def _make_sync_request(self, content=None, source_uri=None,
language_code='en-US',
max_alternatives=max_alternatives,
profanity_filter=True,
speech_context=['Google',
'cloud'])
speech_context=['Google', 'cloud'])
return result

def _check_best_results(self, results):
from google.cloud.speech.transcript import Transcript

top_result = results[0]
self.assertIsInstance(top_result, Transcript)
self.assertEqual(top_result.transcript,
'hello thank you for using Google Cloud platform')
'hello ' + Config.ASSERT_TEXT)
self.assertGreater(top_result.confidence, 0.90)

def test_sync_recognize_local_file(self):
import os
from google.cloud.speech.transcript import Transcript

file_name = os.path.join('system_tests', 'data', 'hello.wav')

with open(file_name, 'rb') as file_obj:
with open(Config.AUDIO_FILE, 'rb') as file_obj:
results = self._make_sync_request(content=file_obj.read(),
max_alternatives=2)
second_alternative = results[1]
self.assertEqual(len(results), 2)
self._check_best_results(results)
self.assertIsInstance(second_alternative, Transcript)
self.assertEqual(second_alternative.transcript,
'thank you for using Google Cloud platform')
self.assertEqual(second_alternative.transcript, Config.ASSERT_TEXT)
self.assertEqual(second_alternative.confidence, 0.0)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


def test_sync_recognize_gcs_file(self):
import os

file_name = os.path.join('system_tests', 'data', 'hello.wav')
bucket_name = Config.TEST_BUCKET.name
blob_name = 'document.txt'
blob_name = 'hello.wav'
blob = Config.TEST_BUCKET.blob(blob_name)
self.to_delete_by_case.append(blob) # Clean-up.
with open(file_name, 'rb') as file_obj:
with open(Config.AUDIO_FILE, 'rb') as file_obj:
blob.upload_from_file(file_obj)

# source_uri = os.getenv('SPEECH_GCS_URI')
source_uri = 'gs://%s/%s' % (bucket_name, blob_name)
result = self._make_sync_request(source_uri=source_uri,
max_alternatives=1)
Expand Down