Use easymidi for Node.js from React Native

275 Views Asked by At

I have a React Native application and in the backend I use Node.js.

Actually I have this in node.js

const easymidi = require('easymidi');
const output = new easymidi.Output('Mindy', true);

function playSound(req, res) {
    console.log('play sound ....');

    const sendNote = (noteValue, duration) => {
        output.send('noteon', noteValue);

        setTimeout(() => {
            output.send('noteoff', noteValue);
        }, duration);
    }

    setInterval(() => {
        const noteValue = {
            note: 12 * 4,
            velocity: 127,
            channel: 1
        }
        sendNote(noteValue, 500);
    }, 1000);

    res.status(200).send({ message: 'play sound' });
}

If I call playSound I have to have a synthesizer running for the sound to be reproduced.

Is there any way to call playSound from React Native application and have this sound be played on the mobile device?

1

There are 1 best solutions below

0
On

easymidi (https://www.npmjs.com/package/easymidi) is built upon node-midi (https://www.npmjs.com/package/midi) that only works on OSX/Windows/Linux. It's unlikely one can make it work on the mobile device. You may want to try some in-browser MIDI libraries: https://www.npmjs.com/search?q=keywords%3Amidi&ranking=popularity