Method for nodejs to send out buzzer sound and of system alarm sound

  • 2021-07-12 04:45:18
  • OfStack

In this paper, an example is given to describe the method of emitting buzzer sound (system alarm sound) by nodejs. Share it for your reference, as follows:

nodejs sometimes requires an alarm sound. Use the following code to call the system buzzer to sound


process.stdout.write('\x07')

Also attached is my own Pomodoro nodejs, which is actually a 25-minute countdown and then beeps


var FANQIE_TIME = 25;
function beep()
{
for(var i =0;i<20;i++)
{
process.stdout.write('\x07')
}
}
var startTime = new Date(); 
var needTime =startTime.setMinutes(startTime.getMinutes()+FANQIE_TIME);
function showTime()
{
var now = new Date();
var totalSecond = Math.floor( (needTime - now)/1000)
if(totalSecond<=0)
{
beep();
if(interVal)
{
clearInterval(interVal);
}
return;
}
var mm =Math.floor(totalSecond/60);
var ss = Math.floor( totalSecond%60);
console.log(mm+":"+ss);
}
var interVal = setInterval(showTime,1000);

I hope this article is helpful to everyone's nodejs programming.


Related articles: