-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathautotune.py
More file actions
56 lines (49 loc) · 2.29 KB
/
autotune.py
File metadata and controls
56 lines (49 loc) · 2.29 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from os import rename, remove, path
from download import download
from pathHelper import *
from subprocessHelper import *
import subprocess, random
# USEWINE = []
USEWINE = ['wine']
loglevel = "error"
def getDur(f):
return eval(subprocess.run(["ffprobe", "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", f], stdout=subprocess.PIPE).stdout)
def autotune(base, over, filename, strength = 75, executableName = "./autotune.exe", reformatAudio = True, hz = 48000):
strength = max(1, min(strength, 512))
if reformatAudio:
baseDur = getDur(base)
loud_run(["ffmpeg", "-y", "-hide_banner", "-loglevel", loglevel, "-i", base, "-ac", "1", "-ar", hz, base := chExt(addPrefix(absPath(base), 'AT_'), 'wav')])
loud_run(["ffmpeg", "-y", "-hide_banner", "-loglevel", loglevel, "-i", over, "-ac", "1", "-ar", hz, '-t', str(baseDur), over := chExt(addPrefix(absPath(over), 'AT_'), 'wav')])
silent_run(USEWINE + [executableName, '-b', strength, base, over, filename])
if reformatAudio:
remove(base)
remove(over)
randDigits = lambda: str(random.random()).replace('.', '')
def autotuneURL(filename, URL, replaceOriginal = True, video = True, executableName = "./autotune.exe"):
directory = path.split(path.abspath(filename))[0]
downloadName = f"{directory}/download_{randDigits()}.wav"
result = download(downloadName, URL, video = False, duration = 2 * 60)
if result:
wavName = f'{directory}/vidAudio_{randDigits()}.wav'
if video:
loud_run(["ffmpeg", "-hide_banner", "-loglevel", loglevel, "-i", filename, "-ac", "1", wavName])
else:
rename(filename, wavName)
autotuneName = f'{directory}/autotune_{randDigits()}.wav'
autotune(wavName, downloadName, autotuneName, executableName = executableName)
remove(downloadName)
remove(wavName)
exportName = f"{directory}/{randDigits()}{path.splitext(filename)[1]}"
if video:
loud_run(["ffmpeg", "-hide_banner", "-loglevel", loglevel, "-i", filename, "-i", autotuneName, "-map", "0:v", "-map", "1:a", "-ac", "1", exportName])
remove(autotuneName)
else:
rename(autotuneName, exportName)
if replaceOriginal:
if video:
remove(filename)
rename(exportName, filename)
return filename
return exportName
else:
return [f"Error downloading {URL}"]