script to amplify voice tracks
This commit is contained in:
48
scripts/amplify-voice-tracks.py
Normal file
48
scripts/amplify-voice-tracks.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#! /usr/bin/env python
|
||||
# pip install -r requirements.txt
|
||||
usage = 'python amplify-voice-tracks.py <cut json> <?wav filename>'
|
||||
|
||||
from imports import *
|
||||
import util
|
||||
from time import sleep
|
||||
import string
|
||||
from os.path import exists
|
||||
from os import system
|
||||
system('color')
|
||||
|
||||
json_filename = util.arg(1, usage)
|
||||
default_wav_name = json_filename.replace('.json', '.wav')
|
||||
wav_filename = util.arg(2, usage, default_wav_name)
|
||||
|
||||
cutter = util.AudioCutter(wav_filename, json_filename)
|
||||
|
||||
new_wav = wav_filename.replace(".wav", f"-amplified.wav")
|
||||
|
||||
def save():
|
||||
cutter.save_and_quit(new_wav)
|
||||
|
||||
def process_chunk(audio_guess, timestamp):
|
||||
audio, length = cutter.audio_and_length(timestamp['start'], timestamp['end'])
|
||||
|
||||
audio_left = [channels[0] for channels in audio]
|
||||
audio_right = [channels[1] for channels in audio]
|
||||
|
||||
def max(l):
|
||||
m = 0
|
||||
m_abs = 0
|
||||
for v in l:
|
||||
if abs(v) > m_abs:
|
||||
m = v
|
||||
m_abs = abs(v)
|
||||
return m
|
||||
ml = max(audio_left)
|
||||
mr = max(audio_right)
|
||||
|
||||
MAX = 32767
|
||||
|
||||
can_multiply = abs(min(MAX/ml, MAX/mr))
|
||||
print(can_multiply)
|
||||
cutter.take_audio(audio_guess, {'start': cutter.current_sec, 'end': cutter.current_sec + length}, timestamp['start'], timestamp['end'], can_multiply)
|
||||
|
||||
cutter.process_audio(process_chunk, new_wav)
|
||||
save()
|
@@ -63,8 +63,15 @@ class AudioCutter:
|
||||
end_frame = int(end * self.framerate)
|
||||
return self.data[start_frame:end_frame], end - start
|
||||
|
||||
def take_audio(self, tag, info, start, end):
|
||||
def take_audio(self, tag, info, start, end, amplify_by=1.0):
|
||||
audio, length = self.audio_and_length(start, end)
|
||||
if amplify_by != 1.0:
|
||||
for idx in range(len(audio)):
|
||||
audio[idx][0] *= amplify_by
|
||||
audio[idx][0] = int(audio[idx][0])
|
||||
audio[idx][1] *= amplify_by
|
||||
audio[idx][1] = int(audio[idx][1])
|
||||
|
||||
self.new_data = vstack((self.new_data, audio))
|
||||
self.current_sec += length
|
||||
self.new_json_info[tag] = info
|
||||
|
Reference in New Issue
Block a user