Skip to content

Commit 92fe2a6

Browse files
committed
Update streaming test and docstrings.
1 parent 0cd0e1c commit 92fe2a6

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

speech/google/cloud/speech/_gax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def streaming_recognize(self, sample, language_code=None,
182182
.cloud_speech_pb2.StreamingRecognizeResponse`
183183
:returns: ``StreamingRecognizeResponse`` instances.
184184
"""
185-
if sample.stream is None or sample.stream.closed:
185+
if sample.stream.closed:
186186
raise ValueError('Stream is closed.')
187187

188188
requests = _stream_requests(sample, language_code=language_code,

speech/google/cloud/speech/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def sample(self, content=None, source_uri=None, stream=None, encoding=None,
7171
"""Factory: construct Sample to use when making recognize requests.
7272
7373
:type content: bytes
74-
:param content: (Optional) Bytes object containing audio data.
74+
:param content: (Optional) Bytes containing audio data.
7575
7676
:type source_uri: str
7777
:param source_uri: (Optional) URI that points to a file that contains

speech/google/cloud/speech/sample.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Sample(object):
2323
"""Representation of an audio sample to be used with Google Speech API.
2424
2525
:type content: bytes
26-
:param content: (Optional) Bytes object containing audio data.
26+
:param content: (Optional) Bytes containing audio data.
2727
2828
:type source_uri: str
2929
:param source_uri: (Optional) URI that points to a file that contains
@@ -59,12 +59,10 @@ def __init__(self, content=None, source_uri=None, stream=None,
5959
encoding=None, sample_rate=None, client=None):
6060
self._client = client
6161

62-
no_source = content is None and source_uri is None and stream is None
63-
both_source = (content is not None
64-
and source_uri is not None
65-
and stream is not None)
66-
if no_source or both_source:
67-
raise ValueError('Supply one of '
62+
sources = [content is not None, source_uri is not None,
63+
stream is not None]
64+
if sources.count(True) != 1:
65+
raise ValueError('Supply exactly one of '
6866
'\'content\', \'source_uri\', \'stream\'')
6967

7068
self._content = content
@@ -124,8 +122,6 @@ def stream(self):
124122
:rtype: file
125123
:returns: File like object to stream.
126124
"""
127-
if getattr(self._stream, 'read', None) is None:
128-
return None
129125
return self._stream
130126

131127
@property

speech/unit_tests/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ def speech_api(channel=None):
459459
speech_api.SERVICE_ADDRESS = host
460460

461461
stream.close()
462+
self.assertTrue(stream.closed)
462463

463-
sample = client.sample(content=stream,
464+
sample = client.sample(stream=stream,
464465
encoding=Encoding.LINEAR16,
465466
sample_rate=self.SAMPLE_RATE)
466467

0 commit comments

Comments
 (0)