streamingDetectIntent method
Stream<StreamingDetectIntentResponse>
streamingDetectIntent(
- InputConfigV2beta1 config,
- Stream<
List< audioStreamint> >
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 biasList = SpeechContextV2Beta1(
phrases: [
'Dialogflow CX',
'Dialogflow Essentials',
'Action Builder',
'HIPAA'
],
boost: 20.0
);
var config = InputConfigV2beta1(
encoding: 'AUDIO_ENCODING_LINEAR_16',
languageCode: 'en-US',
sampleRateHertz: 8000,
singleUtterance: false,
speechContexts: [biasList]
);
final responseStream = dialogflow.streamingDetectIntent(config, _audioStream);
responseStream.listen((data) {
print(data);
});
Implementation
Stream<StreamingDetectIntentResponse> streamingDetectIntent(
InputConfigV2beta1 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);
}