ccieandrew Posted August 1, 2015 Share Posted August 1, 2015 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( "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 Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/ Share on other sites More sharing options...
requinix Posted August 1, 2015 Share Posted August 1, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517849 Share on other sites More sharing options...
ccieandrew Posted August 1, 2015 Author Share Posted August 1, 2015 (edited) 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 Edited August 1, 2015 by ccieandrew Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517850 Share on other sites More sharing options...
requinix Posted August 1, 2015 Share Posted August 1, 2015 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... Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517851 Share on other sites More sharing options...
ccieandrew Posted August 1, 2015 Author Share Posted August 1, 2015 (edited) 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( "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. Edited August 1, 2015 by ccieandrew Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517852 Share on other sites More sharing options...
Solution requinix Posted August 1, 2015 Solution Share Posted August 1, 2015 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() Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517853 Share on other sites More sharing options...
scootstah Posted August 1, 2015 Share Posted August 1, 2015 (edited) 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. Edited August 1, 2015 by scootstah Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517854 Share on other sites More sharing options...
ccieandrew Posted August 1, 2015 Author Share Posted August 1, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/297574-how-to-echo-or-parse/#findComment-1517861 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.