Uploadig each separate part to s3

This commit is contained in:
parth aranke 2024-06-06 22:32:36 +05:30
parent ac29d92fa4
commit eb88e7f9dc
2 changed files with 13 additions and 7 deletions

View File

@ -104,7 +104,6 @@ class ProceesAudio():
modified_seg = add_stereo(final_audios, len(final_audios[0]), sample_rate=sr) modified_seg = add_stereo(final_audios, len(final_audios[0]), sample_rate=sr)
modified_segs.append(modified_seg) modified_segs.append(modified_seg)
modified_segs = np.concatenate(modified_segs)
return modified_segs, part_amps return modified_segs, part_amps
def perform_modulation(self, data, sr, index): def perform_modulation(self, data, sr, index):
@ -118,9 +117,7 @@ class ProceesAudio():
index = int((int(index)/100)*len(x)) index = int((int(index)/100)*len(x))
y = self._get_output_amps(x, index) y = self._get_output_amps(x, index)
y[0][index+1:] *= max_amp
return self.change_amps(new_amps=y[0], sr=sr, data=data) return self.change_amps(new_amps=y[0], sr=sr, data=data)
def get_training_data(self, file_path, data_dir): def get_training_data(self, file_path, data_dir):

View File

@ -21,7 +21,7 @@ def health_check():
return jsonify({"status": "ok"}), 200 return jsonify({"status": "ok"}), 200
@app.route('/process_and_upload', methods=['POST']) @app.route('/process_and_upload', methods=['POST'])
def upload_to_s3(processed_data, userId): def upload_to_s3(processed_data, userId, type):
# Create an in-memory bytes buffer # Create an in-memory bytes buffer
buffer = io.BytesIO() buffer = io.BytesIO()
@ -31,7 +31,7 @@ def upload_to_s3(processed_data, userId):
# Generate a unique file name # Generate a unique file name
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S") timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
s3_key = f'uploads/processed_audio_{userId}_{timestamp}.wav' s3_key = f'uploads/processed_audio_{userId}_{timestamp}_{type}.wav'
# Upload the buffer to AWS S3 # Upload the buffer to AWS S3
s3.upload_fileobj(buffer, BUCKET_NAME, s3_key, ExtraArgs={'ContentType': 'audio/wav'}) s3.upload_fileobj(buffer, BUCKET_NAME, s3_key, ExtraArgs={'ContentType': 'audio/wav'})
@ -69,6 +69,15 @@ def process_audio_bytes(audio_bytes, index):
pa = ProceesAudio() pa = ProceesAudio()
processed_data, part_amps = pa.perform_modulation(data=data, sr=sample_rate, index=index) processed_data, part_amps = pa.perform_modulation(data=data, sr=sample_rate, index=index)
part_urls= []
for i in range(10):
url = upload_to_s3(processed_data=processed_data[i], userId="parth", type="part1")
part_urls.append(url)
processed_data = np.concatenate(processed_data)
file_url = upload_to_s3(processed_data=processed_data, userId="parth") file_url = upload_to_s3(processed_data=processed_data, userId="parth")
arr_to_show = [] arr_to_show = []
@ -89,7 +98,7 @@ def process_audio_bytes(audio_bytes, index):
temp.append(float(part[i])) temp.append(float(part[i]))
ret.append(temp) ret.append(temp)
return jsonify({"file_url": file_url, "array": arr_to_show, "part_amps": ret}) return jsonify({"file_url": file_url, "array": arr_to_show, "part_amps": ret, "part_urls": part_urls})
@app.route('/modify', methods=['POST']) @app.route('/modify', methods=['POST'])
def modify(): def modify():