mp_audio_stream 0.1.5 copy "mp_audio_stream: ^0.1.5" to clipboard
mp_audio_stream: ^0.1.5 copied to clipboard

A simple multi-platform audio stream player for raw audio data streams.

A Flutter plugin for multi-platform, simple audio stream playback with real-time generated audio data streams

Features #

  • Continuously plays buffered audio data at 44.1kHz until the buffer is empty
  • Supported format: float32 multi-channel
  • Suppots all flutter platforms: Android, iOS, macOS, Linux, Windows, and Web platforms
    • Web platform implementaion relies on WebAudio and AudioWorkletProcessor
    • Other platforms utilize miniaudio, an outstandig multi-platform audio library

Getting started #

flutter pub add mp_audio_stream

Usage #

import 'dart:math' as math;
import 'dart:async';
import 'dart:typed_data';

import 'package:mp_audio_stream/mp_audio_stream.dart';

void main() async {
  final audioStream = getAudioStream();

  //default init params: {int bufferMilliSec = 3000,
  //                      int waitingBufferMilliSec = 100,
  //                      int channels = 1,
  //                      int sampleRate = 44100}
  audioStream.init(channels: 2); //Call this from Flutter's State.initState() method

  const rate = 44100;
  const freqL = 440;
  const freqR = 660;
  const dur = 10;
  Float32List samples = Float32List(rate);

  audioStream.resume(); //For the web, call this after user interaction

  for (var t = 0; t < dur; t++) {
    int pos = 0;
    for (var i = 0; i < rate; i++) {
      samples[pos++] = math.sin(2 * math.pi * ((i * freqL) % rate) / rate);
      samples[pos++] = math.sin(2 * math.pi * ((i * freqR) % rate) / rate);
      if (pos == samples.length) {
        pos = 0;
        audioStream.push(samples);
      }
    }
    if (t > 0) {
      await Future.delayed(const Duration(seconds: 1));
    }
  }

  audioStream.uninit(); //Call this from Flutter's State.dispose()
}

For more API Documents, visit pub.dev.

5
likes
120
pub points
73%
popularity

Publisher

unverified uploader

A simple multi-platform audio stream player for raw audio data streams.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

ffi, flutter, flutter_web_plugins, js, plugin_platform_interface

More

Packages that depend on mp_audio_stream