Spaces:
Running
Running
Upload myinfer_latest.py
Browse files- myinfer_latest.py +17 -2
myinfer_latest.py
CHANGED
@@ -175,8 +175,23 @@ def api_convert_voice():
|
|
175 |
|
176 |
if file.content_length > 6 * 1024 * 1024:
|
177 |
return jsonify({"error": "File size exceeds 6 MB"}), 400
|
178 |
-
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
file.seek(0) # Reset file pointer after reading
|
181 |
|
182 |
# Calculate audio length in minutes
|
|
|
175 |
|
176 |
if file.content_length > 6 * 1024 * 1024:
|
177 |
return jsonify({"error": "File size exceeds 6 MB"}), 400
|
178 |
+
|
179 |
+
|
180 |
+
content_type_format_map = {
|
181 |
+
'audio/mpeg': 'mp3',
|
182 |
+
'audio/wav': 'wav',
|
183 |
+
'audio/x-wav': 'wav',
|
184 |
+
'audio/mp4': 'mp4',
|
185 |
+
'audio/x-m4a': 'mp4',
|
186 |
+
}
|
187 |
+
|
188 |
+
# Default to 'mp3' if content type is unknown (or adjust as needed)
|
189 |
+
audio_format = content_type_format_map.get(file.content_type, 'mp3')
|
190 |
+
|
191 |
+
# Convert the uploaded file to an audio segment
|
192 |
+
audio = AudioSegment.from_file(io.BytesIO(file.read()), format=audio_format)
|
193 |
+
|
194 |
+
#audio = AudioSegment.from_file(io.BytesIO(file.read()), format="mp3") # Adjust format as necessary
|
195 |
file.seek(0) # Reset file pointer after reading
|
196 |
|
197 |
# Calculate audio length in minutes
|