Skip to content

Commit

Permalink
Audio Snippet Maker
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-mahajan committed Jun 10, 2019
1 parent 26ea153 commit 0d25ba9
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# audio-cutter

Cut a random sample of the specified length from anywhere with Options

# Variable Usage
```
inputPath - Path of Sample file.
outputPath - Path of output.
seconds - Amount of Time for which sample has be cut.
fadeInOut - Bool - true or false.
fadeInOutTime - Time to fade out - Current = second - 1. i.e. fadeout will start 1 second before ending the file.
setStartTime - Time from where cut has to start.
```
# Steps

```
1. npm install
2. node app.js
```
51 changes: 51 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffmpeg = require('fluent-ffmpeg');
const fs = require('fs');
const inputPath = 'art_of_war_01-02_sun_tzu.ogg'; //Input file Path with Extension
const outputPath = 'output.mp3'; //Output File Path with Extension
const seconds = 300; //Trim Time in seconds
const fadeInOut = true;
let fadeInOutTime = seconds - 1;
const setStartTime = 0; // Start Time
ffmpeg.setFfmpegPath(ffmpegPath);
let audioFilters = []; // Initilizing the Filter
const convert = new ffmpeg({ source: inputPath });

// Conversion of Audio with different options.
try {
// Check if File Exist or Not
if (fs.existsSync(inputPath)) {
//Work if fadeInOut is true.
if (fadeInOut) {
audioFilters = [
{
filter: 'afade',
options: 't=out:st=' + fadeInOutTime + ':d=1'
}
];
} else {
audioFilters = [];
}
// Convert the audio with functionality and output the new File.
convert
.setStartTime(setStartTime) //Can be in "HH:MM:SS" format also
.setDuration(seconds)
.audioFilters(audioFilters)
.on('start', function(command) {
console.log('Actual command Executed: ' + command);
})
.on('error', function(err) {
console.log('error: ', +err);
})
.on('end', function(err) {
if (!err) {
console.log('conversion Done and file saved at: ', outputPath);
}
})
.saveToFile(outputPath);
} else {
throw "File Doesn't Exist";
}
} catch (err) {
console.error(err);
}
85 changes: 85 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "audio-cutter",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Cloudtub",
"license": "ISC",
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.0.17",
"fluent-ffmpeg": "^2.1.2"
}
}

0 comments on commit 0d25ba9

Please sign in to comment.