Sergidev commited on
Commit
5b0a7e4
·
verified ·
1 Parent(s): b2fe4e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -5,7 +5,6 @@ import struct
5
  import logging
6
  from flask import Flask, render_template, request, send_file, jsonify
7
  from werkzeug.utils import secure_filename
8
- from pydub import AudioSegment
9
 
10
  app = Flask(__name__)
11
 
@@ -41,7 +40,7 @@ def process_file():
41
  logger.info(f"File saved: {filepath}")
42
 
43
  factor = int(request.form['factor'])
44
- is_decrypting = filename.lower().endswith('.mp3')
45
  logger.info(f"Processing file: {'decrypting' if is_decrypting else 'encrypting'} with factor {factor}")
46
 
47
  try:
@@ -84,23 +83,12 @@ def encrypt_file(filepath, factor):
84
  wav_output.setframerate(44100)
85
  wav_output.writeframes(struct.pack(f'{len(samples)}h', *samples))
86
 
87
- # Convert WAV to MP3
88
- output.seek(0)
89
- audio = AudioSegment.from_wav(output)
90
- mp3_output = io.BytesIO()
91
- audio.export(mp3_output, format="mp3")
92
-
93
- logger.info(f"Encryption complete. Output size: {mp3_output.getbuffer().nbytes} bytes")
94
- return mp3_output.getvalue(), 'encrypted.mp3', 'audio/mpeg'
95
 
96
  def decrypt_file(filepath, factor):
97
  logger.info(f"Decrypting file: {filepath}")
98
- audio = AudioSegment.from_mp3(filepath)
99
- wav_data = io.BytesIO()
100
- audio.export(wav_data, format="wav")
101
- wav_data.seek(0)
102
-
103
- with wave.open(wav_data, 'rb') as wav_file:
104
  params = wav_file.getparams()
105
  frames = wav_file.readframes(wav_file.getnframes())
106
 
 
5
  import logging
6
  from flask import Flask, render_template, request, send_file, jsonify
7
  from werkzeug.utils import secure_filename
 
8
 
9
  app = Flask(__name__)
10
 
 
40
  logger.info(f"File saved: {filepath}")
41
 
42
  factor = int(request.form['factor'])
43
+ is_decrypting = filename.lower().endswith('.wav')
44
  logger.info(f"Processing file: {'decrypting' if is_decrypting else 'encrypting'} with factor {factor}")
45
 
46
  try:
 
83
  wav_output.setframerate(44100)
84
  wav_output.writeframes(struct.pack(f'{len(samples)}h', *samples))
85
 
86
+ logger.info(f"Encryption complete. Output size: {output.getbuffer().nbytes} bytes")
87
+ return output.getvalue(), 'encrypted.wav', 'audio/wav'
 
 
 
 
 
 
88
 
89
  def decrypt_file(filepath, factor):
90
  logger.info(f"Decrypting file: {filepath}")
91
+ with wave.open(filepath, 'rb') as wav_file:
 
 
 
 
 
92
  params = wav_file.getparams()
93
  frames = wav_file.readframes(wav_file.getnframes())
94