Adding index

This commit is contained in:
parth aranke 2024-06-02 09:47:26 +05:30
parent 965aba39a7
commit 1e24f0cee2

View File

@ -47,7 +47,7 @@ def upload_to_s3(processed_data, userId):
def int16_to_float32(samples): def int16_to_float32(samples):
return samples.astype(np.float32) / 32768.0 return samples.astype(np.float32) / 32768.0
def process_audio_bytes(audio_bytes): def process_audio_bytes(audio_bytes, index):
# Read the audio file from bytes # Read the audio file from bytes
sample_rate, data = wavfile.read(io.BytesIO(audio_bytes)) sample_rate, data = wavfile.read(io.BytesIO(audio_bytes))
left = [] left = []
@ -60,7 +60,8 @@ def process_audio_bytes(audio_bytes):
pa = ProceesAudio() pa = ProceesAudio()
processed_data = pa.perform_modulation(data=data, sr=sample_rate, index=0)
processed_data = pa.perform_modulation(data=data, sr=sample_rate, index=index)
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 = []
@ -79,14 +80,15 @@ def modify():
if 'song' not in request.files: if 'song' not in request.files:
return 'No file part', 400 return 'No file part', 400
file = request.files['song'] file = request.files['song']
index = request.form.get('index') # Assuming index is sent as a form field
if file.filename == '': if file.filename == '':
return 'No selected file', 400 return 'No selected file', 400
if file: if file:
# Read file bytes # Read file bytes
file_bytes = file.read() file_bytes = file.read()
# Process the audio bytes # Process the audio bytes with the index parameter
response = process_audio_bytes(file_bytes) response = process_audio_bytes(file_bytes, index)
response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Origin', '*')
return response return response