-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay-sound.js
More file actions
executable file
·50 lines (39 loc) · 1.2 KB
/
Copy pathplay-sound.js
File metadata and controls
executable file
·50 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
const { exec } = require('child_process');
const { existsSync } = require('fs');
const os = require('os');
const path = require('path');
// Get command line argument for sound type
const soundType = process.argv[2] || 'default';
// Get sound file path
function getSoundFile(type = 'default') {
const homeDir = os.homedir();
const sounds = {
default: path.join(homeDir, 'Music', 'default.mp3'),
notification: path.join(homeDir, 'Music', 'notification.mp3'),
done: path.join(homeDir, 'Music', 'done.mp3'),
};
return sounds[type] || sounds.default;
}
// Play the sound
function playSound() {
const soundFile = getSoundFile(soundType);
if (!existsSync(soundFile)) {
if (process.env.DEBUG) {
console.error(`Sound file not found: ${soundFile}`);
}
return;
}
const command = `ffplay -nodisp -autoexit -v quiet "${soundFile}"`;
if (process.env.DEBUG) {
console.error(`Playing sound: ${soundType}`);
console.error(`Command: ${command}`);
}
exec(command, { timeout: 5000 }, (error) => {
if (error && process.env.DEBUG) {
console.error(`Error playing sound: ${error.message}`);
}
});
}
// Run the script
playSound();