| name | flutter-soloud-output-capture |
| version | 1 |
| description | Teaches how to record the flutter_soloud engine's mixed master output as a Stream<Uint8List> (raw PCM or Opus/Vorbis/FLAC/WAV) using startMixerOutputStream/stopMixerOutputStream, including the WAV header fix-up and capturing from a worker isolate via SoLoudIsolate. Use when the user wants to record, save, or stream what the app is playing (the final mix, NOT microphone input — flutter_soloud does not capture mic), e.g. "save the mix to a .wav file", "record the game audio", "stream the engine output over the network". |
Mixer output capture
flutter_soloud taps the master mixer output: everything the engine mixes (all voices, buses, and active global filters) is copied into a native circular buffer and delivered to Dart as a broadcast Stream<Uint8List> of audio chunks. This is a capture of the output the engine produces — it is not an input device. flutter_soloud has no microphone recording; for mic input use another package. Capture runs on all platforms; on web it requires the WebAssembly build (--wasm).
Minimal example
Record 5 seconds of the mix to a raw PCM file:
import 'dart:io';
import 'package:flutter_soloud/flutter_soloud.dart';
Future<void> recordMix(String outputPath) async {
await SoLoud.instance.init();
final sink = File(outputPath).openWrite();
final stream = SoLoud.instance.startMixerOutputStream(
format: MixerOutputFormat.pcmS16le,
);
final sub = stream.listen(sink.add);
final sound = await SoLoud.instance.loadAsset('assets/music.mp3');
SoLoud.instance.play(sound);
await Future<void>.delayed(const Duration(seconds: 5));
// Stop first: the tail of the buffer is flushed into the stream
// synchronously on stop, so listeners still attached get the last bytes.
SoLoud.instance.stopMixerOutputStream();
await sub.cancel();
await sink.close();
}