Skip to content

Commit 05e7eb6

Browse files
committed
Rename Transcript to Alternative.
1 parent 1d1a729 commit 05e7eb6

File tree

12 files changed

+64
-63
lines changed

12 files changed

+64
-63
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
speech-encoding
179179
speech-operation
180180
speech-sample
181-
speech-transcript
181+
speech-alternative
182182

183183
.. toctree::
184184
:maxdepth: 0

docs/speech-alternative.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Speech Alternative
2+
==================
3+
4+
.. automodule:: google.cloud.speech.alternative
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

docs/speech-transcript.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

speech/google/cloud/speech/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
"""Google Cloud Speech API wrapper."""
1616

17+
from google.cloud.speech.alternative import Alternative
1718
from google.cloud.speech.client import Client
1819
from google.cloud.speech.connection import Connection
1920
from google.cloud.speech.encoding import Encoding
2021
from google.cloud.speech.operation import Operation
21-
from google.cloud.speech.transcript import Transcript

speech/google/cloud/speech/_gax.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
StreamingRecognizeRequest)
2525

2626

27-
from google.cloud.speech.transcript import Transcript
27+
from google.cloud.speech.alternative import Alternative
2828

2929

3030
class GAPICSpeechAPI(object):
@@ -139,7 +139,7 @@ def sync_recognize(self, sample, language_code=None, max_alternatives=None,
139139
if len(api_response.results) == 1:
140140
results = api_response.results.pop()
141141
alternatives = results.alternatives
142-
return [Transcript.from_pb(alternative)
142+
return [Alternative.from_pb(alternative)
143143
for alternative in alternatives]
144144
else:
145145
raise ValueError('More than one result or none returned from API.')
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Transcript representation for Google Speech API"""
15+
"""Representation of Speech Alternative for the Google Speech API."""
1616

1717

18-
class Transcript(object):
19-
"""Representation of Speech Transcripts.
18+
class Alternative(object):
19+
"""Representation of Speech Alternative.
2020
2121
:type transcript: str
2222
:param transcript: String of transcribed data.
@@ -29,33 +29,33 @@ def __init__(self, transcript, confidence):
2929
self._confidence = confidence
3030

3131
@classmethod
32-
def from_api_repr(cls, transcript):
33-
"""Factory: construct ``Transcript`` from JSON response.
32+
def from_api_repr(cls, alternative):
33+
"""Factory: construct ``Alternative`` from JSON response.
3434
35-
:type transcript: dict
36-
:param transcript: Dictionary response from the REST API.
35+
:type alternative: dict
36+
:param alternative: Dictionary response from the REST API.
3737
38-
:rtype: :class:`Transcript`
39-
:returns: Instance of ``Transcript``.
38+
:rtype: :class:`Alternative`
39+
:returns: Instance of ``Alternative``.
4040
"""
41-
return cls(transcript['transcript'], transcript.get('confidence'))
41+
return cls(alternative['transcript'], alternative.get('confidence'))
4242

4343
@classmethod
44-
def from_pb(cls, transcript):
45-
"""Factory: construct ``Transcript`` from protobuf response.
44+
def from_pb(cls, alternative):
45+
"""Factory: construct ``Alternative`` from protobuf response.
4646
47-
:type transcript:
47+
:type alternative:
4848
:class:`google.cloud.speech.v1beta1.SpeechRecognitionAlternative`
49-
:param transcript: Instance of ``SpeechRecognitionAlternative``
49+
:param alternative: Instance of ``SpeechRecognitionAlternative``
5050
from protobuf.
5151
52-
:rtype: :class:`Transcript`
53-
:returns: Instance of ``Transcript``.
52+
:rtype: :class:`Alternative`
53+
:returns: Instance of ``Alternative``.
5454
"""
55-
confidence = transcript.confidence
55+
confidence = alternative.confidence
5656
if confidence == 0.0: # In the protobof 0.0 means unset.
5757
confidence = None
58-
return cls(transcript.transcript, confidence)
58+
return cls(alternative.transcript, confidence)
5959

6060
@property
6161
def transcript(self):

speech/google/cloud/speech/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from google.cloud.speech.encoding import Encoding
2727
from google.cloud.speech.operation import Operation
2828
from google.cloud.speech.sample import Sample
29-
from google.cloud.speech.transcript import Transcript
29+
from google.cloud.speech.alternative import Alternative
3030

3131
try:
3232
from google.cloud.speech._gax import GAPICSpeechAPI
@@ -349,7 +349,7 @@ def sync_recognize(self, sample, language_code=None, max_alternatives=None,
349349

350350
if len(api_response['results']) == 1:
351351
result = api_response['results'][0]
352-
return [Transcript.from_api_repr(alternative)
352+
return [Alternative.from_api_repr(alternative)
353353
for alternative in result['alternatives']]
354354
else:
355355
raise ValueError('More than one result or none returned from API.')

speech/google/cloud/speech/operation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2
1818

1919
from google.cloud import operation
20-
from google.cloud.speech.transcript import Transcript
20+
from google.cloud.speech.alternative import Alternative
2121

2222

2323
operation.register_type(cloud_speech_pb2.AsyncRecognizeMetadata)
@@ -64,5 +64,5 @@ def _update_state(self, operation_pb):
6464
pb_results)
6565

6666
result = pb_results[0]
67-
self.results = [Transcript.from_pb(alternative)
67+
self.results = [Alternative.from_pb(alternative)
6868
for alternative in result.alternatives]
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@
1515
import unittest
1616

1717

18-
class TestTranscript(unittest.TestCase):
18+
class TestAlternative(unittest.TestCase):
1919

2020
def _getTargetClass(self):
21-
from google.cloud.speech.transcript import Transcript
22-
return Transcript
21+
from google.cloud.speech.alternative import Alternative
22+
return Alternative
2323

2424
def _makeOne(self, *args, **kwargs):
2525
return self._getTargetClass()(*args, **kwargs)
2626

2727
def test_constructor(self):
2828
text = 'hello goodbye upstairs'
2929
confidence = 0.5546875
30-
transcript = self._makeOne(text, confidence)
31-
self.assertEqual(transcript._transcript, text)
32-
self.assertEqual(transcript._confidence, confidence)
30+
alternative = self._makeOne(text, confidence)
31+
self.assertEqual(alternative._transcript, text)
32+
self.assertEqual(alternative._confidence, confidence)
3333

3434
def test_transcript_property(self):
3535
text = 'is this thing on?'
36-
transcript = self._makeOne(text, None)
37-
self.assertEqual(transcript.transcript, text)
36+
alternative = self._makeOne(text, None)
37+
self.assertEqual(alternative.transcript, text)
3838

3939
def test_confidence_property(self):
4040
confidence = 0.412109375
41-
transcript = self._makeOne(None, confidence)
42-
self.assertEqual(transcript.confidence, confidence)
41+
alternative = self._makeOne(None, confidence)
42+
self.assertEqual(alternative.confidence, confidence)
4343

4444
def test_from_api_repr_with_no_confidence(self):
4545
data = {
4646
'transcript': 'testing 1 2 3',
4747
}
4848

4949
klass = self._getTargetClass()
50-
transcript = klass.from_api_repr(data)
51-
self.assertEqual(transcript.transcript, data['transcript'])
52-
self.assertIsNone(transcript.confidence)
50+
alternative = klass.from_api_repr(data)
51+
self.assertEqual(alternative.transcript, data['transcript'])
52+
self.assertIsNone(alternative.confidence)
5353

5454
def test_from_pb_with_no_confidence(self):
5555
from google.cloud.grpc.speech.v1beta1 import cloud_speech_pb2
@@ -60,6 +60,6 @@ def test_from_pb_with_no_confidence(self):
6060
self.assertEqual(pb_value.confidence, 0.0)
6161

6262
klass = self._getTargetClass()
63-
transcript = klass.from_pb(pb_value)
64-
self.assertEqual(transcript.transcript, text)
65-
self.assertIsNone(transcript.confidence)
63+
alternative = klass.from_pb(pb_value)
64+
self.assertEqual(alternative.transcript, text)
65+
self.assertIsNone(alternative.confidence)

speech/unit_tests/test_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
7575
from google.cloud._testing import _Monkey
7676
from google.cloud.speech import client as MUT
7777
from google.cloud import speech
78+
from google.cloud.speech.alternative import Alternative
7879
from google.cloud.speech.sample import Sample
79-
from google.cloud.speech.transcript import Transcript
80+
8081
from unit_tests._fixtures import SYNC_RECOGNIZE_RESPONSE
8182

8283
_AUDIO_CONTENT = _to_bytes(self.AUDIO_CONTENT)
@@ -122,18 +123,18 @@ def test_sync_recognize_content_with_optional_params_no_gax(self):
122123
self.assertEqual(req['path'], 'speech:syncrecognize')
123124

124125
alternative = SYNC_RECOGNIZE_RESPONSE['results'][0]['alternatives'][0]
125-
expected = Transcript.from_api_repr(alternative)
126+
expected = Alternative.from_api_repr(alternative)
126127
self.assertEqual(len(response), 1)
127-
self.assertIsInstance(response[0], Transcript)
128+
self.assertIsInstance(response[0], Alternative)
128129
self.assertEqual(response[0].transcript, expected.transcript)
129130
self.assertEqual(response[0].confidence, expected.confidence)
130131

131132
def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
132133
from google.cloud._testing import _Monkey
133134
from google.cloud.speech import client as MUT
134135
from google.cloud import speech
136+
from google.cloud.speech.alternative import Alternative
135137
from google.cloud.speech.sample import Sample
136-
from google.cloud.speech.transcript import Transcript
137138
from unit_tests._fixtures import SYNC_RECOGNIZE_RESPONSE
138139

139140
RETURNED = SYNC_RECOGNIZE_RESPONSE
@@ -164,10 +165,10 @@ def test_sync_recognize_source_uri_without_optional_params_no_gax(self):
164165
self.assertEqual(req['method'], 'POST')
165166
self.assertEqual(req['path'], 'speech:syncrecognize')
166167

167-
expected = Transcript.from_api_repr(
168+
expected = Alternative.from_api_repr(
168169
SYNC_RECOGNIZE_RESPONSE['results'][0]['alternatives'][0])
169170
self.assertEqual(len(response), 1)
170-
self.assertIsInstance(response[0], Transcript)
171+
self.assertIsInstance(response[0], Alternative)
171172
self.assertEqual(response[0].transcript, expected.transcript)
172173
self.assertEqual(response[0].confidence, expected.confidence)
173174

0 commit comments

Comments
 (0)