Easily dub audio files using a simple command script.
Project description
dub-script
Easily dub audio files using a simple command script.
Usage
The example below mixes a voice file from a remote source with a background song.
import dubscript as ds
segment = ds.process({
"version": "3",
"audio": [{
"type": "overlay",
"audio": [
{
"name": "voice",
"start": 500,
"audio": [
{"type": "file", "src": "https://mysite.com/1.wav"},
{"type": "silence", "duration": 1000},
{"type": "file", "src": "https://mysite.com/2.wav"},
]
},
{
"name": "song",
"audio": [
{"type": "file", "src": "local/dir/bg.mp3", "gain": -10}
]
}
]
}]
})
segment.export('podcast.mp3')
Dependencies
dub-script
is powered by Pydub and inherits its dependencies. Install ffmpeg or libav if you need to manipulate non-wave files, like mp3
.
Installation
python setup.py install
Why?
This lib was originally intended to generate a podcast from a few audio files. You can use Pydub for this, but the idea of having a JSON recipe for it has several advantages. Having a recipe means you can version it and keep track of changes. Also, you can easily create a REST API that generates audios using dub-script
. Finally, I find it easier to understand the audio processing when only looking at the JSON.
Commands
With dub-script
, everything is done through commands that follow this basic structure:
{
"type": "<command_type>"
}
The only exception is the concat
command, which doesn't have a type
:
{
"audio": [
// audios to concatenate here
]
}
Load local or remote files
Use file
to load audio data.
{
"type": "file",
// you can have either an url or a path
"src": "<local or remote source>"
}
Add silence
Use silence
to add a silent bit in milliseconds.
{
"type": "silence",
"duration": 1000
}
Concatenate
Join audio together with concatenate:
{
"audio": [
{ "type": "file1.wav" },
{ "type": "file2.wav" }
// ...
]
}
Overlay
Mix audio tracks that plays at the same time with overlay
.
Note: the length of the overlaid audio will always be equal to the first audio in the series.
{
"type": "overlay",
"audio": [
// holds the tracks
{
"name": "track1", // track names are not required and are only here for organization purposes (yet)
"start": 3000, // this track will be delayed by 3 seconds
"audio": [{ "type": "file1.wav" }, { "type": "file2.wav" }]
},
{
"audio": [{ "type": "file3.wav" }],
"gain": 5 // the previous track will be boosted by +5 db while they overlap
}
]
}
Filters
Filters can be applied to any other command.
Change volume
You can change the volume with gain
. For instance:
{
"type": "file",
"src": "quiet.wav",
"gain": 3
}
Fade In/Out
Fade audio with either fade_in
or fade_out
:
{
"audio": [
{
"type": "file",
"src": "intro.mp3",
"fade_in": 3000 // fade the first 3 seconds
},
{
"type": "file",
"src": "main.mp3",
"fade_out": 10000 // fade the last 10 seconds
}
]
}
License
Licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file dubscript-0.1-py3-none-any.whl
.
File metadata
- Download URL: dubscript-0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cbb4b2ac3c6f620295bf284e40f79e09082fa37aae01d11b6bb4626dfa50d23 |
|
MD5 | 8d7b71a500fbe54c70a89ca8c3233ebf |
|
BLAKE2b-256 | e46ce6ad03f0fad911debd24bdc70fdfa34136c771f2dcfe3b0fae6b07280cbf |