-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay.ts
More file actions
42 lines (37 loc) · 836 Bytes
/
play.ts
File metadata and controls
42 lines (37 loc) · 836 Bytes
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
import { execSync } from "child_process";
import { platform } from "os";
// grabbed from https://github.com/shime/play-sound/blob/master/index.js
const players = [
"mplayer",
"afplay",
"mpg123",
"mpg321",
"play",
"omxplayer",
"aplay",
"cmdmp3",
"cvlc",
"powershell",
];
export default function play(what) {
if (!what) {
throw new Error("No audio specified");
}
const player = findExec(players);
if (!what) {
throw new Error("No audio player found");
}
Bun.spawnSync([player, what], {});
}
function findExec(commands: Array = []) {
let command = null;
for (const c of commands) {
try {
const check = /^win/.test(platform) ? `where ${c}` : `command -v ${c}`;
execSync(check, { stdio: "ignore" });
command = c;
break;
} catch (_e) {}
}
return command;
}