flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

[HELP]: Web: Record to Stream

Open hagen00 opened this issue 1 year ago • 1 comments

Is there support for recording to a stream on web? I'm playing around with code as per below (just shots in the dark).

On web, it's not hitting the listen method, i.e not printing Adding to sink WEB. I've also played around with only calling toStream, but then I get a mismatch with initialiizing recordingDataController as StreamController<Uint8List>().

The record method is working fine on a native Android device.

Future<void> record() async {
    var webRecordingDataController = StreamController<List<Float32List>>();
    var recordingDataController = StreamController<Uint8List>();

    _mRecordingDataSubscription = recordingDataController.stream.listen((buffer) {
      print('Adding to sink--------- ');
      voiceChannel!.sink.add(buffer);
    });
    _mRecordingDataSubscription = webRecordingDataController.stream.listen((buffer) {
      print('Adding to sink WEB!!!!!!!!!!!!!!!!!---------');
      voiceChannel!.sink.add(buffer);
    });
    await mRecorder!.startRecorder(
      toStream: kIsWeb ? null : recordingDataController.sink,
      toStreamFloat32: kIsWeb ? webRecordingDataController.sink : null,
      codec: kIsWeb ? Codec.opusWebM : Codec.pcm16,
      numChannels: 1,
      sampleRate: 24000,
      bufferSize: 8192,
    );
  }

Anyone gotten recording to stream on web to work?

hagen00 avatar Jan 07 '25 10:01 hagen00

Flutter Sound 9.21.1 is released. It implements Float 32 not interleaved stream on Web. I will work on Int16 and interleaved format on web later. See this guide and this example

9.21.1

  • playFromMic() is deprecated

  • feedFromStream() is deprecated

  • foodSink getter is deprecated

  • startPlayerFromStream() with back pressure is deprecated

  • startPlayerFromStream() : no more whenFinished parameter

  • add functions feedUint8FromStream(), feedInt16FromStream() and feedF32FromStream()

  • add getters uint8ListSink, float32Sink and int16Sink

  • On web : startPlayerFromStream() is implemented for codec.pcmFloat32 and not interleaved

  • TODO

    • On Web : Implement Streams Int16
    • On Web : Implement Stream interleaved.

Larpoux avatar Feb 03 '25 17:02 Larpoux