Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files- myinfer_latest.py +15 -0
myinfer_latest.py
CHANGED
@@ -27,6 +27,8 @@ from threading import Semaphore
|
|
27 |
from threading import Lock
|
28 |
from multiprocessing import Process, SimpleQueue, set_start_method,get_context
|
29 |
from queue import Empty
|
|
|
|
|
30 |
|
31 |
|
32 |
|
@@ -170,6 +172,19 @@ def api_convert_voice():
|
|
170 |
file = request.files['file']
|
171 |
if file.filename == '':
|
172 |
return jsonify({"error": "No selected file"}), 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
#created_files = []
|
174 |
# Save the file to a temporary path
|
175 |
unique_id = str(uuid.uuid4())
|
|
|
27 |
from threading import Lock
|
28 |
from multiprocessing import Process, SimpleQueue, set_start_method,get_context
|
29 |
from queue import Empty
|
30 |
+
from pydub import AudioSegment
|
31 |
+
import io
|
32 |
|
33 |
|
34 |
|
|
|
172 |
file = request.files['file']
|
173 |
if file.filename == '':
|
174 |
return jsonify({"error": "No selected file"}), 400
|
175 |
+
|
176 |
+
if file.content_length > 6 * 1024 * 1024:
|
177 |
+
return jsonify({"error": "File size exceeds 6 MB"}), 400
|
178 |
+
|
179 |
+
audio = AudioSegment.from_file(io.BytesIO(file.read()), format="wav") # Adjust format as necessary
|
180 |
+
file.seek(0) # Reset file pointer after reading
|
181 |
+
|
182 |
+
# Calculate audio length in minutes
|
183 |
+
audio_length_minutes = len(audio) / 60000.0 # pydub returns length in milliseconds
|
184 |
+
|
185 |
+
if audio_length_minutes > 3:
|
186 |
+
return jsonify({"error": "Audio length exceeds 3 minutes"}), 400
|
187 |
+
|
188 |
#created_files = []
|
189 |
# Save the file to a temporary path
|
190 |
unique_id = str(uuid.uuid4())
|