Using s3 instead of firebase

This commit is contained in:
parth aranke 2024-06-02 06:06:06 +05:30
parent f2eb3c05bc
commit 8f73af8776

View File

@ -6,46 +6,36 @@ import librosa
from Utils import ProceesAudio from Utils import ProceesAudio
import soundfile as sf import soundfile as sf
import datetime import datetime
import boto3
from flask_jwt_extended import JWTManager, jwt_required, create_access_token, get_jwt_identity from flask_jwt_extended import JWTManager, jwt_required, create_access_token, get_jwt_identity
app = Flask(__name__) app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # 16 MB limit app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024 # 16 MB limit
# AWS S3 Configuration
# Firebase configuration s3 = boto3.client('s3')
# firebase_config = { BUCKET_NAME = 'songsbucketparth'
# "apiKey": "AIzaSyBqDZlqD7UOBvt2zsk9OLWKH1Lc3_f_VJM",
# "authDomain": "modifier-4088b.firebaseapp.com",
# "projectId": "modifier-4088b",
# "storageBucket": "modifier-4088b.appspot.com",
# "messagingSenderId": "237119475630",
# "appId": "1:237119475630:web:6c96c38c61285f5fcb823f",
# "measurementId": "G-6CWLQMT2Q3",
# "databaseURL": "https://modifier-4088b.firebaseio.com",
# }
# firebase = pyrebase.initialize_app(firebase_config)
# storage = firebase.storage()
@app.route('/process_and_upload', methods=['POST']) @app.route('/process_and_upload', methods=['POST'])
def upload_to_s3(processed_data, userId):
# Create an in-memory bytes buffer
buffer = io.BytesIO()
# def upload_to_firebase(processed_data, userId): # Write processed data to the buffer as a WAV file
# # Create an in-memory bytes buffer sf.write(buffer, processed_data, 44100, format='WAV')
# buffer = io.BytesIO() buffer.seek(0) # Rewind the buffer
# # Write processed data to the buffer as a WAV file # Generate a unique file name
# sf.write(buffer, processed_data, 44100, format='WAV') timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
# buffer.seek(0) # Rewind the buffer s3_key = f'uploads/processed_audio_{userId}_{timestamp}.wav'
# # Upload the buffer to Firebase Storage # Upload the buffer to AWS S3
# storage_path = f'uploads/processed_audio_{userId}.wav' s3.upload_fileobj(buffer, BUCKET_NAME, s3_key, ExtraArgs={'ContentType': 'audio/wav'})
# storage.child(storage_path).put(buffer, f'processed_audio_{userId}.wav')
# # Get the URL of the uploaded file # Generate the URL of the uploaded file
# file_url = storage.child(storage_path).get_url(None) file_url = f'https://{BUCKET_NAME}.s3.amazonaws.com/{s3_key}'
# return file_url
return file_url
def int16_to_float32(samples): def int16_to_float32(samples):
return samples.astype(np.float32) / 32768.0 return samples.astype(np.float32) / 32768.0
@ -64,7 +54,7 @@ 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=0)
# file_url = upload_to_firebase(processed_data=processed_data, userId="parth") file_url = upload_to_s3(processed_data=processed_data, userId="parth")
arr_to_show = [] arr_to_show = []
acc_factor = int(len(processed_data)/150) acc_factor = int(len(processed_data)/150)
@ -75,7 +65,7 @@ def process_audio_bytes(audio_bytes):
for i in range(len(arr_to_show)): for i in range(len(arr_to_show)):
arr_to_show[i] = float(arr_to_show[i]) arr_to_show[i] = float(arr_to_show[i])
return jsonify({"file_url": "", "array": arr_to_show}) return jsonify({"file_url": file_url, "array": arr_to_show})
@app.route('/modify', methods=['POST']) @app.route('/modify', methods=['POST'])
def modify(): def modify():