From 93adea864935f8023ca63fb9186d263b3744697e Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Sun, 17 Jan 2021 17:05:45 +0100 Subject: [PATCH 1/2] Use ffmpeg for lower latency audio --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6c7ee9e..9bd8f71 100755 --- a/index.js +++ b/index.js @@ -8,6 +8,12 @@ if (process.argv.length < 3) { process.exit(1) } +const osAudioMap = { + linux: 'alsa', + darwin: 'avfoundation', + windows: 'dshow' +} + let record let play @@ -21,10 +27,10 @@ beam.on('remote-address', function ({ host, port }) { beam.on('connected', function () { console.error('[hyperbeam] Success! Encrypted tunnel established to remote peer') - record = spawn('sox', ['-q', '--buffer', '512', '-d', '-r', '44100', '-c', '1', '-e', 'signed-integer', '-b', '16', '-t', 'wav', '-'], { + record = spawn('ffmpeg', ['-f', osAudioMap[process.platform], '-i', 'default', '-fflags', 'nobuffer', '-ar', '44100', '-vn', '-f', 'mpegts', '-v', '8', '-hide_banner', '-'], { stdio: ['inherit', 'pipe', 'inherit' ] }) - play = spawn('play', ['-q', '--buffer', '512', '-'], { + play = spawn('ffplay', ['-f', 'mpegts', '-probesize', '32', '-analyzeduration', '0', '-af', 'adeclick=w=10:o=50', '-i', '-v', '8', '-hide_banner', '-nodisp', '-'], { stdio: ['pipe', 'inherit', 'inherit' ] }) record.stdout.pipe(beam).pipe(play.stdin) From 9095d54c26191ccfa3a6a0d6c82a8f3788f118c1 Mon Sep 17 00:00:00 2001 From: Bendik Aagaard Lynghaug Date: Sun, 17 Jan 2021 20:57:51 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e58444d..9d0991e 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,18 @@ A telephone over [Hyperbeam](https://github.com/mafintosh/hyperbeam) npm install -g hyperphone ``` -Needs sox installed. +Needs ffmpeg installed. On mac: ```sh -brew install sox +brew install ffmpeg ``` On linux: ```sh -sudo apt-get install sox +sudo apt-get install ffmpeg ``` ## Usage