streamingDetectIntent method
Processes a natural language query in audio format in a streaming fashion and returns structured, actionable data as a result. This method is only available via the gRPC API (not REST). Sends a StreamingDetectIntentResponse to the Dialogflow API Requires a InputAudioConfig and an audioStream.
var config = InputConfig(
encoding: 'AUDIO_ENCODING_LINEAR_16',
languageCode: 'en-US',
sampleRateHertz: 8000
);
final responseStream = dialogflow.streamingDetectIntent(config, _audioStream);
responseStream.listen((data) {
print(data);
});
Implementation
Stream<StreamingDetectIntentResponse> streamingDetectIntent(
InputConfigV2 config, Stream<List<int>> audioStream) {
// Create the stream, which later transmits the necessary
// data to the Google API
final request = StreamController<StreamingDetectIntentRequest>();
// add the session to the request
// print(DialogflowAuth.session);
QueryInput queryInput = QueryInput()..audioConfig = config.cast();
print(queryInput);
request
.add(StreamingDetectIntentRequest()
..queryInput = queryInput
..session = DialogflowAuth.session
);
// Send the request first
// Afterwards start streaming the audio
_audioStreamSubscription = audioStream.listen((audio) {
// Add audio content when stream changes.
request.add(StreamingDetectIntentRequest()..inputAudio = audio);
});
_audioStreamSubscription.onDone(() {
// Close the request stream, if the audio stream is finished.
request.close();
});
return client.streamingDetectIntent(request.stream);
}