wave_builder 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • new60

A builder for Wave files. This utility can create the byte list to write a wave file, concatenating other wave files and periods of silence.

This utility is designed specifically to make metronome files (click tracks), but can be used for other applications as well.

Created from templates made available by Stagehand under a BSD-style license.

Usage #

A simple usage example:

import 'package:wave_builder/wave_builder.dart';

/// Create 1 bar of a 4/4 metronome at 60 BPM
main() {
  var fileOut = File('./example/assets/out/test.wav');
  var primary = File('./example/assets/wav/primary.wav');
  var secondary = File('./example/assets/wav/secondary.wav');
  var silenceType = WaveBuilderSilenceType.BeginningOfLastSample;

  var primaryBytes = await primary.readAsBytes();
  var secondaryBytes = await secondary.readAsBytes();

  await fileOut.create();

  var waveBuilder = WaveBuilder();

  waveBuilder.appendFileContents(primaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  waveBuilder.appendFileContents(secondaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  waveBuilder.appendFileContents(secondaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  waveBuilder.appendFileContents(secondaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  await fileOut.writeAsBytes(waveBuilder.fileBytes);
}

1.0.0 #

  • Initial version, created by Stagehand
  • Supports adding wave files and silence.
  • Bit rate, frequency, and number of channels (mono/stereo) are hardcoded.

1.0.1 #

  • Fixed a couple typos in docs, created/updated docs.
  • Allow audio properties (frequency, bit rate, and number of channels) to be passed in instead of hardcoded.

1.0.2 #

  • No code changes, but homepage is now reachable (so it will pass that analysis).

1.0.3 #

  • Updated home page to github repository.

1.0.4 #

  • Optimizations to adding files.
  • Supports finding the data chunk first, to prevent repeating the iteration many times.

example/wave_builder_example.dart

import 'dart:io';

import 'package:wave_builder/wave_builder.dart';

Future<void> main() async {
  var fileOut = File('./example/assets/out/test.wav');
  var primary = File('./example/assets/wav/primary.wav');
  var secondary = File('./example/assets/wav/secondary.wav');
  var silenceType = WaveBuilderSilenceType.BeginningOfLastSample;

  var primaryBytes = await primary.readAsBytes();
  var secondaryBytes = await secondary.readAsBytes();

  if (await fileOut.exists()) {
    await fileOut.delete();
  }

  await fileOut.create();

  var waveBuilder = WaveBuilder();

  waveBuilder.appendFileContents(primaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  waveBuilder.appendFileContents(secondaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  waveBuilder.appendFileContents(secondaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  waveBuilder.appendFileContents(secondaryBytes);
  waveBuilder.appendSilence(1000, silenceType);
  await fileOut.writeAsBytes(waveBuilder.fileBytes);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  wave_builder: ^1.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:wave_builder/wave_builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
20
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0