Closed 00j closed 5 years ago
Hi @00j,
I did some testing and found that the query result is not returned in the final streamed response. You should inspect the streamed response and set $queryResult
within the loop rather than attempting to grab it from the final iteration.
$queryResult = null;
foreach ($stream->closeWriteAndReadAll() as $i => $response) {
$recognitionResult = $response->getRecognitionResult();
if ($recognitionResult) {
$transcript = $recognitionResult->getTranscript();
printf('Intermediate transcript: %s' . PHP_EOL, $transcript);
}
$queryResult = !$queryResult && $response->getQueryResult()
? $response->getQueryResult()
: $queryResult;
}
if ($queryResult) {
echo $queryResult->getQueryText();
}
You should be sure to check that $queryResult
is not null before calling a method on the instance which you expect the variable to contain.
Hi John,
Thank you very much for your prompt response and highlighting the problem.
Following a quick test, It appears that when output audio config is not used the getQueryResult()
is set on the last iteration of:
foreach ($stream->closeWriteAndReadAll() as $response)
Where as when output audio config is used then getQueryResult()
is set on the penultimate iteration, as you indicated.
My example was lifted from a php-docs-samples sample:
I'll post a recommendation for an update.
Thanks again for your help, very much appreciated Jamie
Hello, Please could I ask for some help?
When I attempt to 'Detect Intent' on an example utterance and also request synthesised TTS using OutputAudioConfig() the DialogFlow API throws the following exception:
PHP Fatal error: Uncaught Error: Call to a member function getQueryText() on null in ..........\detect-intent-stream.php:191
It appears 'query_result' in StreamingDetectIntentResponse.php isn't populated when getting the response.
Is this expected?
Environment details
Steps to reproduce
Please see examples.
Code example
To demonstrate the problem I've used the Meeting demo Agent and the standard detect intent stream example script as follows.
With example 1 you can see the example outputs the intermediate transcription and finally the detected intent and fulfilment text.
However with example 2 we see the exception after the intermediate transcription.
Example Audio
bookmeeting.zip
Composer Show for google/cloud
Thank you!