Add dockerfile

This commit is contained in:
Sravanth C 2021-01-20 01:12:29 +05:30
parent 1e72f69ce6
commit 8b2d2a3b34
No known key found for this signature in database
GPG key ID: D3A98BAD2354B432
5 changed files with 165 additions and 30 deletions

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM node:lts-alpine3.12
RUN mkdir -p /usr/src/bot
WORKDIR /usr/src/bot
COPY package.json /usr/src/bot
RUN npm install
COPY . /usr/src/bot
CMD ["node", "index.js"]

View file

@ -9,8 +9,9 @@ _Recording voice calls without prior consent violates privacy. Do not use this b
<img src="https://i.imgur.com/y6JCNNA.png" width="400" align="center">
- [Installation and Usage](#installation-and-usage)
- [Setting Up the Local Environment](#setting-up-the-local-environment)
- [Running the Script](#running-the-script)
- [Run Locally](#run-locally)
- [Run as Docker Container](#run-as-docker-container)
- [Bot Commands](#bot-commands)
- [Managing the Output](#managing-the-output)
- [Merge Recording](#merge-recording)
- [Convert the Merged File to MP3](#convert-the-merged-file-to-mp3)
@ -23,11 +24,7 @@ Clone the repository :
git clone https://github.com/chebro/discord-voice-recorder/
```
Run `npm i` to download necessary `node_modules`. Then, head over to the [FFmpeg.org](https://ffmpeg.org/download.html), and download executables for your OS; If you're on Windows, double-check if the FFmpeg bin is on your path.
### Setting Up the Local Environment
To run this script locally, [create a discord bot](https://discordpy.readthedocs.io/en/latest/discord.html) first. Invite the bot to your server, then:
[Create a discord bot](https://discordpy.readthedocs.io/en/latest/discord.html). Invite the bot to your server, then:
1. Create a `config.json` file and a `recordings` folder at the root folder.
2. Paste the bot token (from [developer window](https://discord.com/developers/applications)) and any bot prefix into `config.json`, like so:
@ -39,50 +36,62 @@ To run this script locally, [create a discord bot](https://discordpy.readthedocs
}
```
### Running the Script
You can run the bot in any one of the following two ways.
Run `npm start`, the bot should be online.
### Running the Script Locally
#### Start Recording
Run `npm i` to download necessary `node_modules`, then run `npm start`, the bot should be online.
### Run as a Docker Container
1. Build the docker image
```
<PREFIX>enter <VOICE_CHANNEL_NAME>
docker build -t dvr .
```
**Note:** You should hear a 'drop' sound after running this. If you don't, there's a problem with your FFmpeg installation.
#### Stop Recording
2. Bind `/recordings` directory on host to container and start the container with a custom name.
```
<PREFIX>exit
docker run \
--name <CONTAINER_NAME> \
--mount type=bind,source="$(pwd)"/recordings,target=/usr/src/bot/recordings \
dvr
```
The bot should be online.
3. To stop the container, run `docker stop <CONTAINER_NAME>`, you can restart it using `docker start <CONTINAER_NAME>`.
### Bot Commands
1. Start Recording : `<PREFIX>enter <VOICE_CHANNEL_NAME>`
2. Stop Recording : `<PREFIX>exit`
## Managing the Output
The audio will be recorded in [PCM format](https://en.wikipedia.org/wiki/Pulse-code_modulation) and saved to the `/recordings` directory.
_To work with PCM audio, you could use software such as [Audacity](https://www.audacityteam.org/). To import the audio into Audacity, open File > Import Raw Data... and then select your audio file. You should select Signed 16-bit PCM as the encoding, a Little-endian byte order, 2 Channels (Stereo) and a sample rate of 48000Hz._
The output for each piece of audio stream is written to a unique file in [PCM format](https://en.wikipedia.org/wiki/Pulse-code_modulation) (48000 Hz, signed 16-bit little-endian, 2 channel [stereo]) and saved to the `/recordings` directory.
### Merge Recording
The output for each piece of audio stream is written to a unique file. To merge all output files, run:
To merge all output files to `/recordings/merge.pcm`, run:
```
node ./bin/merge.js
node /bin/merge.js
```
This creates a `merge.pcm` in the `/recordings` directory.
**Note:** Do not forget to empty your `recordings` folder after each session. Running `./bin/merge.js` otherwise, will dump large merge files.
**Note:** Empty your `recordings` folder (and remove `merge.pcm`) after each session. Running `./bin/merge.js` otherwise, will dump large merge files.
### Convert the Merged File to MP3
As mentioned in issue [#3](https://github.com/chebro/discord-voice-recorder/issues/3), to convert pcm to mp3, run:
Head over to [FFmpeg.org](https://ffmpeg.org/download.html), and download executables for your OS; If you're on Windows, double-check if the FFmpeg bin is on your path. As discussed in issue [#3](https://github.com/chebro/discord-voice-recorder/issues/3), to convert pcm to mp3, run:
```
ffmpeg -f s16le -ar 44.1k -ac 2 -i merge.pcm output.mp3
ffmpeg -f s16le -ar 48000 -ac 2 -i merge.pcm output.mp3
```
## Thanks
Special thanks to [@eslachance](https://github.com/eslachance) for the [gist](https://gist.github.com/eslachance/fb70fc036183b7974d3b9191601846ba). It is what inspired me to make this repo.

View file

@ -1,8 +1,8 @@
var fs = require('fs'),
chunks = fs.readdirSync('../recordings'),
chunks = fs.readdirSync(__dirname + '/../recordings'),
inputStream,
currentfile,
outputStream = fs.createWriteStream('../recordings/merge.pcm');
outputStream = fs.createWriteStream(__dirname + '/../recordings/merge.pcm');
chunks.sort((a, b) => { return a - b; });
@ -12,7 +12,7 @@ function appendFiles() {
return;
}
currentfile = '../recordings/' + chunks.shift();
currentfile = `${__dirname}/../recordings/` + chunks.shift();
inputStream = fs.createReadStream(currentfile);
inputStream.pipe(outputStream, { end: false });
@ -23,4 +23,5 @@ function appendFiles() {
});
}
appendFiles();
appendFiles();

113
package-lock.json generated
View file

@ -4,6 +4,17 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@derhuerst/http-basic": {
"version": "8.2.1",
"resolved": "https://registry.npmjs.org/@derhuerst/http-basic/-/http-basic-8.2.1.tgz",
"integrity": "sha512-Rmn7qQQulw2sxJ8qGfZ7OuqMWuhz8V+L5xnYKMF5cXVcYqmgWqlVEAme90pF7Ya8OVhxVxLmhh0rI2k6t7ITWw==",
"requires": {
"caseless": "^0.12.0",
"concat-stream": "^1.6.2",
"http-response-object": "^3.0.1",
"parse-cache-control": "^1.0.1"
}
},
"@discordjs/collection": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
@ -45,6 +56,11 @@
"node-addon-api": "^2.0.0"
}
},
"@types/node": {
"version": "10.17.51",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.51.tgz",
"integrity": "sha512-KANw+MkL626tq90l++hGelbl67irOJzGhUJk6a1Bt8QHOeh9tztJx+L0AqttraWKinmZn7Qi5lJZJzx45Gq0dg=="
},
"abbrev": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@ -58,6 +74,24 @@
"event-target-shim": "^5.0.0"
}
},
"agent-base": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz",
"integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==",
"requires": {
"debug": "4"
},
"dependencies": {
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"requires": {
"ms": "2.1.2"
}
}
}
},
"ansi-regex": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz",
@ -96,6 +130,16 @@
"concat-map": "0.0.1"
}
},
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
},
"chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz",
@ -119,6 +163,17 @@
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"concat-stream": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
"requires": {
"buffer-from": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^2.2.2",
"typedarray": "^0.0.6"
}
},
"console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
@ -172,11 +227,27 @@
"ws": "^7.3.1"
}
},
"env-paths": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz",
"integrity": "sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA=="
},
"event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
},
"ffmpeg-static": {
"version": "4.2.7",
"resolved": "https://registry.npmjs.org/ffmpeg-static/-/ffmpeg-static-4.2.7.tgz",
"integrity": "sha512-SGnOr2d+k0/9toRIv9t5/hN/DMYbm5XMtG0wVwGM1tEyXJAD6dbcWOEvfHq4LOySm9uykKL6LMC4eVPeteUnbQ==",
"requires": {
"@derhuerst/http-basic": "^8.2.0",
"env-paths": "^2.2.0",
"https-proxy-agent": "^5.0.0",
"progress": "^2.0.3"
}
},
"fs-minipass": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",
@ -223,6 +294,33 @@
"resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz",
"integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk="
},
"http-response-object": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/http-response-object/-/http-response-object-3.0.2.tgz",
"integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==",
"requires": {
"@types/node": "^10.0.3"
}
},
"https-proxy-agent": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
"integrity": "sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==",
"requires": {
"agent-base": "6",
"debug": "4"
},
"dependencies": {
"debug": {
"version": "4.3.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz",
"integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==",
"requires": {
"ms": "2.1.2"
}
}
}
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -427,6 +525,11 @@
"os-tmpdir": "^1.0.0"
}
},
"parse-cache-control": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-cache-control/-/parse-cache-control-1.0.1.tgz",
"integrity": "sha1-juqz5U+laSD+Fro493+iGqzC104="
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
@ -442,6 +545,11 @@
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
},
"progress": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA=="
},
"rc": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz",
@ -566,6 +674,11 @@
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

View file

@ -14,6 +14,7 @@
},
"dependencies": {
"@discordjs/opus": "^0.3.2",
"discord.js": "^12.3.1"
"discord.js": "^12.3.1",
"ffmpeg-static": "^4.2.7"
}
}