In flutter/dart, How I can record a stream of MIDI (soundfonts, sf2 extention) to a WAV/PCM-16/MP3 (other audio format) file?

In general, I'm trying to record the user selected notes (which run every X time by using stream mechanism).

=> And I would like to record his/her session to a audio file.

Thanks in advance :).

1

There are 1 answers

0
randyrand On

Use DartMeltySoundFont

import 'package:dart_melty_soundfont/dart_melty_soundfont.dart';
import 'package:flutter/services.dart' show rootBundle;

// Create the synthesizer.
ByteData bytes = await rootBundle.load('assets/akai_steinway.sf2');

Synthesizer synth = Synthesizer.loadByteData(bytes);

// Turn on some notes
synth.noteOn(channel: 0, key: 72, velocity: 120);
synth.noteOn(channel: 0, key: 76, velocity: 120);
synth.noteOn(channel: 0, key: 79, velocity: 120);

// Render the waveform (3 seconds)
ArrayInt16 buf16 = ArrayInt16.zeros(numShorts: 44100 * 3);
synth.renderMonoInt16(buf16);