Adding changes required for furthur editing
This commit is contained in:
parent
4f9a670aa7
commit
c7fddcaae4
16
Utils.py
16
Utils.py
@ -59,7 +59,7 @@ class ProceesAudio():
|
||||
model = BigramLanguageModel()
|
||||
model.to("cpu", dtype=float)
|
||||
model.load_state_dict(torch.load('amp_net.pth', map_location=torch.device('cpu')))
|
||||
return model.generate(torch.tensor(input_amps[:index+1]).view(1, index+1, len(input_amps[0])).to(self.device), len(input_amps)-index + 1)
|
||||
return model.generate(torch.tensor(input_amps[:index+1]).view(1, index+1, len(input_amps[0])).to(self.device), len(input_amps)-index - 1)
|
||||
|
||||
def make_smooth(self, audio, gain, prev_gain):
|
||||
smooth_index = 1000
|
||||
@ -77,22 +77,27 @@ class ProceesAudio():
|
||||
max_amp = max(max_amp, np.max(np.abs(segment)))
|
||||
|
||||
x, _ = self._calculate_average_amplitude(segments=segments, sr=sr)
|
||||
#print(x.shape)
|
||||
|
||||
index = int((int(index)/100)*len(x))
|
||||
|
||||
y = self._get_output_amps(x, index)
|
||||
print(len(y), len(x))
|
||||
modified_segs = []
|
||||
prev_gains = np.ones(10)
|
||||
|
||||
max_part_amp = 0
|
||||
|
||||
for segment, mod in zip(segments, y[0]):
|
||||
_, audios = split_stereo(segment=segment, max_amp=max_amp, sr=sr, num_parts=10)
|
||||
final_audios = []
|
||||
curr_gains = []
|
||||
|
||||
for audio, target_amp, i in zip(audios, mod, range(10)):
|
||||
|
||||
gain = (target_amp.item()/np.mean(np.abs(audio)))*max_amp
|
||||
|
||||
if np.mean(np.abs(audio)) == 0:
|
||||
gain=0
|
||||
elif gain <= 50:
|
||||
elif gain <= 50 and gain >=1:
|
||||
gain = gain/50
|
||||
else:
|
||||
gain=1
|
||||
@ -105,6 +110,9 @@ class ProceesAudio():
|
||||
modified_seg = add_stereo(final_audios, len(final_audios[0]), sample_rate=sr)
|
||||
modified_segs.append(modified_seg)
|
||||
|
||||
modified_segs[:index+1] = segments[:index+1]
|
||||
|
||||
|
||||
modified_segs = np.concatenate(modified_segs)
|
||||
return modified_segs.astype(np.float32)
|
||||
|
||||
|
@ -64,7 +64,7 @@ def process_audio_bytes(audio_bytes, index):
|
||||
|
||||
pa = ProceesAudio()
|
||||
|
||||
processed_data = pa.perform_modulation(data=data, sr=sample_rate, index=index)
|
||||
processed_data, part_amps = pa.perform_modulation(data=data, sr=sample_rate, index=index)
|
||||
file_url = upload_to_s3(processed_data=processed_data, userId="parth")
|
||||
arr_to_show = []
|
||||
|
||||
@ -76,7 +76,7 @@ def process_audio_bytes(audio_bytes, index):
|
||||
for i in range(len(arr_to_show)):
|
||||
arr_to_show[i] = float(arr_to_show[i])
|
||||
|
||||
return jsonify({"file_url": file_url, "array": arr_to_show})
|
||||
return jsonify({"file_url": file_url, "array": arr_to_show, "part_amps": float(part_amps)})
|
||||
|
||||
@app.route('/modify', methods=['POST'])
|
||||
def modify():
|
||||
|
Loading…
Reference in New Issue
Block a user