You can use something like this (adapt it to your Bela setup)
SynthDef(\onsets_trigger, { | inChan = 0, trigID = 1, threshold = 0.2, floor = 0.2 |
var in, chain;
in = SoundIn.ar(inChan);
chain = FFT(LocalBuf(2048), in);
chain = Onsets.kr(chain, threshold: threshold, odftype: \wphase, relaxtime: 100, floor: floor, mingap: 10, medianspan: 200);
SendTrig.kr(chain, 2, trigID); //Send the time recorded to the language
SendTrig.kr(Impulse.kr(20), 20, Amplitude.kr(in)); // Send the amplitude of the
}).add;
And then you catch the OSC messages:
OSCdef.new(\recResponder,
{ |msg, time, addr, recvPort|
var num = msg[2].asInt;
//msg.postln;
switch(num)
{2} {
("onset" + msg[3].asInt.asString + Date.getDate.rawSeconds.asString).postln;
//trigger sound
switch(msg[3].asInt) // if you have different triggers with different IDs you can differentiate between them
{2} {};
}
{20} // Amplitude from onsets_trigger
{
var amp = msg[3].asFloat;
};
}, path: "/tr");