-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeNightcore.py
41 lines (28 loc) · 1.28 KB
/
MakeNightcore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import tempfile
import subprocess
import argparse
from pydub import AudioSegment
def nightcore(input_file, output_file):
song = AudioSegment.from_file(input_file)
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as input_wav_file, tempfile.NamedTemporaryFile(
suffix=".wav", delete=False) as output_wav_file:
song.export(input_wav_file.name, format="wav")
command = f"rubberband -t 0.85 -p 3 \"{input_wav_file.name}\" \"{output_wav_file.name}\""
subprocess.run(command, shell=True, check=True)
output_song = AudioSegment.from_file(output_wav_file.name)
output_song.export(output_file, format="wav")
input_wav_file.close()
os.remove(input_wav_file.name)
output_wav_file.close()
os.remove(output_wav_file.name)
def main():
parser = argparse.ArgumentParser(description="Create a nightcore version of an input audio file.")
parser.add_argument("-s", "--source", required=True, help="Path to the input audio file")
parser.add_argument("-o", "--output", default="nightcore_version.wav", help="Path to the output audio file")
args = parser.parse_args()
input_file = args.source
output_file = args.output
nightcore(input_file, output_file)
if __name__ == "__main__":
main()