1
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(); 

我试图在单击每个 UI 框时播放音调。我onclick添加到框中的事件不起作用。console.log作品但没有音调。单击ui框时如何播放音调?引用stream仍然存在,我可以在不接收null. 溪流也仍然开放。

4

0 回答 0