Reputation: 751
const ToneStream = require('tone-stream')
const Speaker = require('speaker');
const blessed = require('blessed');
const format = {
sampleRate: 8000,
bitDepth: 16,
channels: 1
}
let stream = new ToneStream(format);
const speaker = new Speaker(format);
stream.pipe(speaker);
var screen = blessed.screen({
smartCSR: true
});
let boxarray = [];
for(let i = 0; i < 10; i++) {
let box = blessed.box({
top: "0%",
left: (i/10 *100).toString() + '%',
width: (1/11 *100).toString() + '%',
height: "100%",
tags: true,
style: {
bg: "white"
}
});
box.on('click', () => {
stream.add([4000, 440]);
console.log(i);
});
boxarray.push(box);
}
boxarray.forEach((box) => {
screen.append(box);
});
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
screen.render();
I'm trying to get a tone to play when each UI box is clicked. My onclick
event added to the boxes isn't working. The console.log
works but no tone is played. How can I get a tone to play when a ui box is clicked? The reference to stream
still exists, I can console log it without receiving null
. The stream is also still open.
Upvotes: 1
Views: 140