Merge pull request #9 from chebro/add-dockerfile

Merge add-dockerfile
This commit is contained in:
chebro 2021-01-20 01:21:18 +05:30 committed by GitHub
commit 9b29f38a9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 30 deletions

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"> <img src="https://i.imgur.com/y6JCNNA.png" width="400" align="center">
- [Installation and Usage](#installation-and-usage) - [Installation and Usage](#installation-and-usage)
- [Setting Up the Local Environment](#setting-up-the-local-environment) - [Run Locally](#run-locally)
- [Running the Script](#running-the-script) - [Run as Docker Container](#run-as-docker-container)
- [Bot Commands](#bot-commands)
- [Managing the Output](#managing-the-output) - [Managing the Output](#managing-the-output)
- [Merge Recording](#merge-recording) - [Merge Recording](#merge-recording)
- [Convert the Merged File to MP3](#convert-the-merged-file-to-mp3) - [Convert the Merged File to MP3](#convert-the-merged-file-to-mp3)
@ -23,13 +24,9 @@ Clone the repository :
git clone https://github.com/chebro/discord-voice-recorder/ 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. [Make a discord bot](https://discordpy.readthedocs.io/en/latest/discord.html) if you don't have one already and invite the bot to your server, then:
### Setting Up the Local Environment 1. Create `config.json` file and a `/recordings` directory at the root folder.
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:
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: 2. Paste the bot token (from [developer window](https://discord.com/developers/applications)) and any bot prefix into `config.json`, like so:
```yaml ```yaml
@ -39,50 +36,62 @@ To run this script locally, [create a discord bot](https://discordpy.readthedocs
} }
``` ```
### Running the Script You can now run the script in one of the following two ways:
Run `npm start`, the bot should be online. ### Run 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. 2. Bind `/recordings` directory on host to container and start the container with a custom name:
#### Stop Recording
``` ```
<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 ## 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. 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.
_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._
### Merge Recording ### 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:** Empty your `recordings` folder (and remove `merge.pcm`) after each session. Running `./bin/merge.js` otherwise, will dump large merge files.
**Note:** Do not forget to empty your `recordings` folder after each session. Running `./bin/merge.js` otherwise, will dump large merge files.
### Convert the Merged File to MP3 ### 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 ## 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. 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'), var fs = require('fs'),
chunks = fs.readdirSync('../recordings'), chunks = fs.readdirSync(__dirname + '/../recordings'),
inputStream, inputStream,
currentfile, currentfile,
outputStream = fs.createWriteStream('../recordings/merge.pcm'); outputStream = fs.createWriteStream(__dirname + '/../recordings/merge.pcm');
chunks.sort((a, b) => { return a - b; }); chunks.sort((a, b) => { return a - b; });
@ -12,7 +12,7 @@ function appendFiles() {
return; return;
} }
currentfile = '../recordings/' + chunks.shift(); currentfile = `${__dirname}/../recordings/` + chunks.shift();
inputStream = fs.createReadStream(currentfile); inputStream = fs.createReadStream(currentfile);
inputStream.pipe(outputStream, { end: false }); inputStream.pipe(outputStream, { end: false });
@ -23,4 +23,5 @@ function appendFiles() {
}); });
} }
appendFiles(); appendFiles();