You've already forked fm-dx-webserver
mirror of
https://github.com/KubaPro010/fm-dx-webserver.git
synced 2026-02-26 14:11:59 +01:00
Merge pull request #175 from bkram/fix/fix-macos-audio-device-selection
Fix: fix macOS audio device selection.
This commit is contained in:
@@ -18,9 +18,9 @@ function connectMessage(message) {
|
|||||||
function checkAudioUtilities() {
|
function checkAudioUtilities() {
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
try {
|
try {
|
||||||
execSync('which rec');
|
execSync('which sox');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(`${consoleLogTitle} Error: SoX ("rec") not found. Please install SoX.`);
|
logError(`${consoleLogTitle} Error: SoX ("sox") not found, Please install sox.`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else if (process.platform === 'linux') {
|
} else if (process.platform === 'linux') {
|
||||||
@@ -62,11 +62,11 @@ function buildCommand(ffmpegPath) {
|
|||||||
} else if (process.platform === 'darwin') {
|
} else if (process.platform === 'darwin') {
|
||||||
// macOS
|
// macOS
|
||||||
if (!serverConfig.audio.ffmpeg) {
|
if (!serverConfig.audio.ffmpeg) {
|
||||||
logInfo(`${consoleLogTitle} Platform: macOS (darwin) using "coreaudio" with the default audio device.`);
|
logInfo(`${consoleLogTitle} Platform: macOS (darwin) using "coreaudio"`);
|
||||||
return {
|
return {
|
||||||
args: [],
|
args: [],
|
||||||
recArgs: [
|
soxArgs: [
|
||||||
'-t', 'coreaudio',
|
'-t', 'coreaudio', `${inputDevice}`,
|
||||||
'-b', '32',
|
'-b', '32',
|
||||||
'-r', '48000',
|
'-r', '48000',
|
||||||
'-c', `${audioChannels}`,
|
'-c', `${audioChannels}`,
|
||||||
@@ -228,54 +228,53 @@ checkFFmpeg().then((ffmpegPath) => {
|
|||||||
}
|
}
|
||||||
launchFFmpeg(); // Initial launch
|
launchFFmpeg(); // Initial launch
|
||||||
} else if (process.platform === 'darwin') {
|
} else if (process.platform === 'darwin') {
|
||||||
// macOS (rec --> 3las.server.js --> FFmpeg)
|
// macOS (sox --> 3las.server.js --> FFmpeg)
|
||||||
const commandDef = buildCommand(ffmpegPath);
|
const commandDef = buildCommand(ffmpegPath);
|
||||||
|
|
||||||
// Apply audio boost if enabled and FFmpeg is used
|
// Apply audio boost if enabled and FFmpeg is used
|
||||||
if (serverConfig.audio.audioBoost && serverConfig.audio.ffmpeg) {
|
if (serverConfig.audio.audioBoost && serverConfig.audio.ffmpeg) {
|
||||||
commandDef.args.splice(commandDef.recArgs.indexOf('pipe:1'), 0, '-af', 'volume=1.7');
|
commandDef.args.splice(commandDef.soxArgs.indexOf('pipe:1'), 0, '-af', 'volume=1.7');
|
||||||
}
|
}
|
||||||
|
|
||||||
let currentRec = null;
|
let currentSox = null;
|
||||||
|
|
||||||
process.on('exit', () => {
|
process.on('exit', () => {
|
||||||
if (currentRec) currentRec.kill('SIGINT');
|
if (currentSox) currentSox.kill('SIGINT');
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('SIGINT', () => {
|
process.on('SIGINT', () => {
|
||||||
if (currentRec) currentRec.kill('SIGINT');
|
if (currentSox) currentSox.kill('SIGINT');
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
|
||||||
function startRec() {
|
function startSox() {
|
||||||
if (!serverConfig.audio.ffmpeg) {
|
if (!serverConfig.audio.ffmpeg) {
|
||||||
// Spawn rec
|
// Spawn sox
|
||||||
logDebug(`${consoleLogTitle} Launching rec with args: ${commandDef.recArgs.join(' ')}`);
|
logDebug(`${consoleLogTitle} Launching sox with args: ${commandDef.soxArgs.join(' ')}`);
|
||||||
|
|
||||||
//const rec = spawn(commandDef.command, { shell: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
const sox = spawn('sox', commandDef.soxArgs, { stdio: ['ignore', 'pipe', 'pipe'] });
|
||||||
const rec = spawn('rec', commandDef.recArgs, { stdio: ['ignore', 'pipe', 'pipe'] });
|
currentSox = sox;
|
||||||
currentRec = rec;
|
|
||||||
|
|
||||||
audioServer.waitUntilReady.then(() => {
|
audioServer.waitUntilReady.then(() => {
|
||||||
audioServer.Server.StdIn = rec.stdout;
|
audioServer.Server.StdIn = sox.stdout;
|
||||||
audioServer.Server.Run();
|
audioServer.Server.Run();
|
||||||
connectMessage(`${consoleLogTitle} Connected rec \u2192 FFmpeg \u2192 Server.StdIn${serverConfig.audio.audioBoost && serverConfig.audio.ffmpeg ? ' (audio boost)' : ''}`);
|
connectMessage(`${consoleLogTitle} Connected SoX \u2192 FFmpeg \u2192 Server.StdIn${serverConfig.audio.audioBoost && serverConfig.audio.ffmpeg ? ' (audio boost)' : ''}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
rec.stderr.on('data', (data) => {
|
sox.stderr.on('data', (data) => {
|
||||||
logFfmpeg(`[rec stderr]: ${data}`);
|
logFfmpeg(`[sox stderr]: ${data}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
rec.on('exit', (code) => {
|
sox.on('exit', (code) => {
|
||||||
logFfmpeg(`[rec exited] with code ${code}`);
|
logFfmpeg(`[sox exited] with code ${code}`);
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
setTimeout(startRec, 2000);
|
setTimeout(startSox, 2000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
startRec();
|
startSox();
|
||||||
|
|
||||||
if (serverConfig.audio.ffmpeg) {
|
if (serverConfig.audio.ffmpeg) {
|
||||||
logDebug(`${consoleLogTitle} Launching FFmpeg with args: ${commandDef.args.join(' ')}`);
|
logDebug(`${consoleLogTitle} Launching FFmpeg with args: ${commandDef.args.join(' ')}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user