streamingRecognize method

Stream<StreamingRecognizeResponse> streamingRecognize(
  1. StreamingRecognitionConfigBeta config,
  2. Stream<List<int>> audioStream
)

Sends a StreamingRecognizeRequest to the Google Speech Api. Requires a StreamingRecognitionConfig and an audioStream.

Implementation

Stream<StreamingRecognizeResponse> streamingRecognize(
    StreamingRecognitionConfigBeta config, Stream<List<int>> audioStream) {
  final client = SpeechClient(_channel, options: _options);

  // Create the stream, which later transmits the necessary
  // data to the Google Api.
  final request = StreamController<StreamingRecognizeRequest>();

  // Send the streaming config at first.
  request
      .add(StreamingRecognizeRequest()..streamingConfig = config.toConfig());

  _audioStreamSubscription = audioStream.listen((audio) {
    // Add audio content when stream changes.
    request.add(StreamingRecognizeRequest()..audioContent = audio);
  });

  _audioStreamSubscription!.onDone(() {
    // Close the request stream, if the audio stream is finished.
    request.close();
  });
  return client.streamingRecognize(request.stream);
}