Jump to content

How to echo or parse


ccieandrew

Recommended Posts

I have a code  where the result for $response is

 

object(Att\Api\Speech\SpeechResponse)#8 (3) { ["_responseId":"Att\Api\Speech\SpeechResponse":private]=> string(32) "0135b50eb1a47009d4ef5af98bce7c9a" ["_status":"Att\Api\Speech\SpeechResponse":private]=> string(2) "OK" ["_NBest":"Att\Api\Speech\SpeechResponse":private]=> object(Att\Api\Speech\NBest)#7 (7) { ["_hypothesis":"Att\Api\Speech\NBest":private]=> string(14) "Boston Celtics" ["_languageId":"Att\Api\Speech\NBest":private]=> string(5) "en-US" ["_confidence":"Att\Api\Speech\NBest":private]=> float(0.239999995) ["_grade":"Att\Api\Speech\NBest":private]=> string(6) "accept" ["_resultText":"Att\Api\Speech\NBest":private]=> string(15) "Boston Celtics." ["_words":"Att\Api\Speech\NBest":private]=> array(2) { [0]=> string(6) "Boston" [1]=> string( 8) "Celtics." } ["_wordScores":"Att\Api\Speech\NBest":private]=> array(2) { [0]=> float(0.239) [1]=> float(0.239) } } }

 

 

I would like to be able to display 

responseId: "ee1996d19d959aa0acac6d0240159b6e"
status: "OK" 
hypothesis: "boston celtics" 
languageId:  "en-US" 
grade:  "accept" 
resultText:  "Boston celtics." 
 
 

I'm trying echo $response->resultText but it doesn't work

 

Help

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/
Share on other sites

All of those properties are private. You can tell because every single one says "private".

 

Look for a method on the object that you should call.

 

 

Thanks for the info.  Attached show the method on the object.

 

I was able to use the code below to display responseid and status.  But not the others including the resulttext. 

 

echo 'responseId: ' . $response->getResponseId() . "<br \>";
echo 'status: ' . $response->getStatus() . "<br \>";
 
I tried echo 'nBest: ' . $response->getNBest(ResultText);
but I got an error that it's not a string....
 
Can you help me with the proper syntax.
 
Thanks

NBest.php

SpeechResponse.php

That the return value from getNBest is not a string? Well what is it then? I bet you it's an object and that you'll have to call a method on it...

 

based on the var_dump

object(Att\Api\Speech\SpeechResponse)#8 (3) { ["_responseId":"Att\Api\Speech\SpeechResponse":private]=> string(32) "0135b50eb1a47009d4ef5af98bce7c9a" ["_status":"Att\Api\Speech\SpeechResponse":private]=> string(2) "OK" ["_NBest":"Att\Api\Speech\SpeechResponse":private]=> object(Att\Api\Speech\NBest)#7 (7) { ["_hypothesis":"Att\Api\Speech\NBest":private]=> string(14) "Boston Celtics" ["_languageId":"Att\Api\Speech\NBest":private]=> string(5) "en-US" ["_confidence":"Att\Api\Speech\NBest":private]=> float(0.239999995) ["_grade":"Att\Api\Speech\NBest":private]=> string(6) "accept" ["_resultText":"Att\Api\Speech\NBest":private]=> string(15) "Boston Celtics." ["_words":"Att\Api\Speech\NBest":private]=> array(2) { [0]=> string(6) "Boston" [1]=> string(  8)"Celtics." } ["_wordScores":"Att\Api\Speech\NBest":private]=> array(2) { [0]=> float(0.239) [1]=> float(0.239) } } }

 

 

The responseId and Status are strings.  But NBest is an Object which hold hypothesis, resulttext, etc

 

There is a funtion getNBest (SpeechResponse.php)

The file NBest.php has a function getHypothesis() and getResultText().

 

I'm guessing the call would be something like 

echo $response->getNBest[NBest.ResultText];

No error but just blank display.  I can't figure out the syntax 

 

 

Thanks for your help.

Look at the getNBest() method. Is there documentation for this stuff? If not, look at the code. It probably does not take any arguments and it probably returns that _NBest object. Apparently that class has getHypothesis() and getResultText() methods, so you need to call them. Not on the response but on the NBest object.

$response->getNBest()->getHypothesis()

requinix is correct. See here: https://github.com/attdevsupport/ATT_APIPlatform_SampleApps/blob/master/RESTFul/Speech/PHP/app1/lib/Speech/NBest.php

 

See all of those "getX()" functions? Those are called "getters", to retrieve the private/protected properties of a class, which is very common in object-oriented programming.

 

EDIT: Oops, didn't see the file was uploaded here. Guess I google'd for nothing. Oh well.

Look at the getNBest() method. Is there documentation for this stuff? If not, look at the code. It probably does not take any arguments and it probably returns that _NBest object. Apparently that class has getHypothesis() and getResultText() methods, so you need to call them. Not on the response but on the NBest object.

$response->getNBest()->getHypothesis()

 

Thank you very much for your help.  This is the exact syntax that I need.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.