File tree Expand file tree Collapse file tree 3 files changed +12
-6
lines changed
Expand file tree Collapse file tree 3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,12 @@ See: `Speech Asynchronous Recognize`_
6969 ... operation.poll() # API call
7070 >> > operation.complete
7171 True
72- >> > operation.results[0 ].transcript
72+ >> > for result in operation.results:
73+ ... print (' =' * 20 )
74+ ... print (result.transcript)
75+ ... print (result.confidence)
76+ ====================
7377 ' how old is the Brooklyn Bridge'
74- >> > operation.results[0 ].confidence
7578 0.98267895
7679
7780
Original file line number Diff line number Diff line change @@ -123,8 +123,9 @@ def _update(self, response):
123123 raw_results = response .get ('response' , {}).get ('results' , None )
124124 results = []
125125 if raw_results :
126- for result in raw_results [0 ]['alternatives' ]:
127- results .append (Transcript .from_api_repr (result ))
126+ for result in raw_results :
127+ for alternative in result ['alternatives' ]:
128+ results .append (Transcript .from_api_repr (alternative ))
128129 if metadata :
129130 self ._metadata = Metadata .from_api_repr (metadata )
130131
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ def test_ctor_defaults(self):
3636
3737 def test_from_api_repr (self ):
3838 from unit_tests ._fixtures import OPERATION_COMPLETE_RESPONSE
39- from google .cloud .speech .operation import Transcript
39+ from google .cloud .speech .transcript import Transcript
4040 from google .cloud .speech .metadata import Metadata
4141 RESPONSE = OPERATION_COMPLETE_RESPONSE
4242
@@ -46,10 +46,12 @@ def test_from_api_repr(self):
4646 self .assertEqual ('123456789' , operation .name )
4747 self .assertTrue (operation .complete )
4848
49+ self .assertEqual (len (operation .results ), 1 )
4950 self .assertIsInstance (operation .results [0 ], Transcript )
5051 self .assertEqual (operation .results [0 ].transcript ,
5152 'how old is the Brooklyn Bridge' )
52- self .assertEqual (operation .results [0 ].confidence , 0.98267895 )
53+ self .assertEqual (operation .results [0 ].confidence ,
54+ 0.98267895 )
5355 self .assertTrue (operation .complete )
5456 self .assertIsInstance (operation .metadata , Metadata )
5557 self .assertEqual (operation .metadata .progress_percent , 100 )
You can’t perform that action at this time.
0 commit comments