Skip to content

Conversation

@daspecster
Copy link
Contributor

First swing at system tests for sync_recognize().

The GCS test is using a file(hello.wav) on my bucket so we'll probably want to upload that to the testing account.

@daspecster daspecster added testing api: speech Issues related to the Speech-to-Text API. labels Oct 15, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 15, 2016
import monitoring
import pubsub
import storage
import speech

This comment was marked as spam.

This comment was marked as spam.

import io
from google.cloud import speech
client = speech.Client()
file_name = 'system_tests/data/hello.wav'

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

client = speech.Client()
file_name = 'system_tests/data/hello.wav'

with io.open(file_name, 'rb') as file_obj:

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):
from google.cloud import speech
client = speech.Client()
source_uri = 'gs://ferrous-arena-my-test-bucket/hello.wav'

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):
from google.cloud import speech
client = speech.Client()

This comment was marked as spam.

speech_context=['Google', 'cloud'])
self.assertEqual(res[0].transcript,
'hello thank you for using Google Cloud platform')
self.assertEqual(len(res), 1)

This comment was marked as spam.

sample = client.sample(content=file_obj.read(),
encoding=speech.Encoding.LINEAR16,
sample_rate=16000)
res = client.sync_recognize(sample,

This comment was marked as spam.

max_alternatives=2,
profanity_filter=True,
speech_context=['Google', 'cloud'])
self.assertEqual(res[0].transcript,

This comment was marked as spam.

speech_context=['Google', 'cloud'])
self.assertEqual(res[0].transcript,
'hello thank you for using Google Cloud platform')
self.assertEqual(len(res), 2)

This comment was marked as spam.

@daspecster
Copy link
Contributor Author

@dhermes, I had to change how the transcript and confidence values are accessed. I think I was running this before with a different version installed so I had them as properties. The result for sync _recognize is currently a dictionary.

@dhermes
Copy link
Contributor

dhermes commented Oct 20, 2016

I had to change how the transcript and confidence values are accessed. I think I was running this before with a different version installed so I had them as properties

It's tough to review a moving target. Are the tested methods done and checked in? If yes, then why the out-of-sync issue?

max_alternatives=1)
self.assertEqual(result[0]['transcript'],
'hello thank you for using Google Cloud platform')
self.assertGreater(result[0]['confidence'], .90)

This comment was marked as spam.

result = self._make_sync_request(content=file_obj.read(),
max_alternatives=2)

self.assertEqual(result[0]['transcript'],

This comment was marked as spam.

def test_sync_recognize_gcs_file(self):
import os

source_uri = os.getenv('SPEECH_GCS_URI')

This comment was marked as spam.

return result

def test_sync_recognize_local_file(self):
file_name = 'system_tests/data/hello.wav'

This comment was marked as spam.


self.assertEqual(result[0]['transcript'],
'hello thank you for using Google Cloud platform')
self.assertGreater(result[0]['confidence'], .90)

This comment was marked as spam.


def _make_sync_request(self, content=None, source_uri=None,
max_alternatives=None):
from google.cloud.speech.encoding import Encoding

This comment was marked as spam.

@daspecster daspecster force-pushed the add-speech-sync-system-tests branch from da3d0c9 to c30ea2f Compare October 27, 2016 15:44

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.

max_alternatives=max_alternatives,
profanity_filter=True,
speech_context=['Google',
'cloud'])

This comment was marked as spam.

return result

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

This comment was marked as spam.


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

This comment was marked as spam.

import os
from google.cloud.speech.transcript import Transcript

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

This comment was marked as spam.

self.assertIsInstance(second_alternative, Transcript)
self.assertEqual(second_alternative.transcript,
'thank you for using Google Cloud platform')
self.assertEqual(second_alternative.confidence, 0.0)

This comment was marked as spam.

This comment was marked as spam.

self._check_best_results(results)
self.assertIsInstance(second_alternative, Transcript)
self.assertEqual(second_alternative.transcript,
'thank you for using Google Cloud platform')

This comment was marked as spam.

with open(file_name, 'rb') as file_obj:
blob.upload_from_file(file_obj)

# source_uri = os.getenv('SPEECH_GCS_URI')

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')

This comment was marked as spam.


file_name = os.path.join('system_tests', 'data', 'hello.wav')
bucket_name = Config.TEST_BUCKET.name
blob_name = 'document.txt'

This comment was marked as spam.

This comment was marked as spam.

CLIENT = None
TEST_BUCKET = None
AUDIO_FILE = os.path.join(os.path.dirname(__file__), 'data', 'hello.wav')
ASSERT_TEXT = 'thank you for using Google Cloud platform'

This comment was marked as spam.

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

This comment was marked as spam.

self._check_best_results(results)
self.assertIsInstance(second_alternative, Transcript)
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.

@daspecster daspecster merged commit cc505bd into googleapis:master Oct 27, 2016
@daspecster daspecster mentioned this pull request Oct 27, 2016
14 tasks
@daspecster daspecster deleted the add-speech-sync-system-tests branch January 24, 2017 15:17
richkadel pushed a commit to richkadel/google-cloud-python that referenced this pull request May 6, 2017
…stem-tests

Add Speech sync recognize system test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: speech Issues related to the Speech-to-Text API. cla: yes This human has signed the Contributor License Agreement. testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants