Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
3 changes: 3 additions & 0 deletions speech/google/cloud/speech/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

"""Google Cloud Speech API wrapper."""

import pkg_resources
__version__ = pkg_resources.get_distribution('google-cloud-speech').version

from google.cloud.speech.alternative import Alternative
from google.cloud.speech.client import Client
from google.cloud.speech.encoding import Encoding
Expand Down
10 changes: 8 additions & 2 deletions speech/google/cloud/speech/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from google.cloud._helpers import make_secure_stub
from google.cloud._http import DEFAULT_USER_AGENT

from google.cloud.speech import __version__
from google.cloud.speech.operation import Operation
from google.cloud.speech.result import Result

Expand All @@ -45,12 +46,17 @@ def __init__(self, client=None):
channel = make_secure_channel(
credentials, DEFAULT_USER_AGENT,
SpeechClient.SERVICE_ADDRESS)
self._gapic_api = SpeechClient(channel=channel)
self._gapic_api = SpeechClient(
channel=channel,
lib_name='gccl',
lib_version=__version__,
)
self._operations_stub = make_secure_stub(
credentials,
DEFAULT_USER_AGENT,
operations_grpc.OperationsStub,
OPERATIONS_API_HOST)
OPERATIONS_API_HOST,

This comment was marked as spam.

)

def async_recognize(self, sample, language_code=None,
max_alternatives=None, profanity_filter=None,
Expand Down
4 changes: 2 additions & 2 deletions speech/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
REQUIREMENTS = [
'google-cloud-core >= 0.23.0, < 0.24dev',
'grpcio >= 1.0.2, < 2.0dev',
'gapic-google-cloud-speech-v1beta1 >= 0.15.0, < 0.16dev',
'gapic-google-cloud-speech-v1beta1 >= 0.15.1, < 0.16dev',
]

setup(
name='google-cloud-speech',
version='0.22.0',
version='0.23.0',

This comment was marked as spam.

This comment was marked as spam.

description='Python Client for Google Cloud Speech',
long_description=README,
namespace_packages=[
Expand Down
23 changes: 23 additions & 0 deletions speech/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@

import unittest

import mock

import google.auth.credentials


class TestGAPICSpeechAPI(unittest.TestCase):
def test_kwarg_lib_name(self):
from google.cloud.speech import Client
from google.cloud.speech import __version__
from google.cloud.gapic.speech.v1beta1 import speech_client

# Mock the creation of the actual GAPIC speech client.
with mock.patch.object(speech_client.SpeechClient, '__init__') as sc:
sc.return_value = None

# Ensure that the lib_name and lib_version arguments
# are passed as expected.
client = Client()
client.speech_api
sc.assert_called_once()
self.assertEqual(sc.mock_calls[0][2]['lib_name'], 'gccl')
self.assertEqual(sc.mock_calls[0][2]['lib_version'], __version__)


class TestSpeechGAXMakeRequests(unittest.TestCase):
SAMPLE_RATE = 16000
Expand Down
38 changes: 21 additions & 17 deletions speech/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(response=_make_sync_response(),
channel=channel)
channel=channel, **kwargs)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -311,10 +311,10 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(
response=_make_sync_response(result),
channel=channel)
channel=channel, **kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -407,8 +407,8 @@ def make_channel(*args):
encoding=speech.Encoding.LINEAR16,
sample_rate=self.SAMPLE_RATE)

def speech_api(channel=None):
return _MockGAPICSpeechAPI(channel=channel)
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(channel=channel, **kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -463,8 +463,8 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
return _MockGAPICSpeechAPI(channel=channel)
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(channel=channel, **kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -522,8 +522,9 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
return _MockGAPICSpeechAPI(channel=channel, response=responses)
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(channel=channel, response=responses,
**kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -599,8 +600,9 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
return _MockGAPICSpeechAPI(channel=channel, response=responses)
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(channel=channel, response=responses,
**kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -643,8 +645,9 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
return _MockGAPICSpeechAPI(channel=channel, response=responses)
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(channel=channel, response=responses,
**kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -677,8 +680,8 @@ def make_channel(*args):
channel_args.append(args)
return channel_obj

def speech_api(channel=None):
return _MockGAPICSpeechAPI(channel=channel)
def speech_api(channel=None, **kwargs):
return _MockGAPICSpeechAPI(channel=channel, **kwargs)

host = 'foo.apis.invalid'
speech_api.SERVICE_ADDRESS = host
Expand Down Expand Up @@ -720,9 +723,10 @@ class _MockGAPICSpeechAPI(object):

SERVICE_ADDRESS = 'foo.apis.invalid'

def __init__(self, response=None, channel=None):
def __init__(self, response=None, channel=None, **kwargs):
self._response = response
self._channel = channel
self._kwargs = kwargs

def async_recognize(self, config, audio):
from google.gapic.longrunning.operations_client import OperationsClient
Expand Down