Spaces:
Build error
Build error
Kartikeyssj2
commited on
Commit
•
c3b89d9
1
Parent(s):
55eda9f
Update main.py
Browse files
main.py
CHANGED
@@ -11,8 +11,15 @@ import io
|
|
11 |
import random
|
12 |
import tempfile
|
13 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
os.environ['NUMBA_DISABLE_JIT'] = '1'
|
16 |
MultiPartParser.max_file_size = 200 * 1024 * 1024
|
17 |
|
18 |
# Initialize FastAPI app
|
@@ -101,8 +108,11 @@ async def upload_audio(file: UploadFile = File(...)):
|
|
101 |
print("Uploaded file saved to:", temp_file_path)
|
102 |
|
103 |
# Load the audio file using librosa with a fixed sample rate of 16000 Hz
|
104 |
-
audio, sr =
|
105 |
-
|
|
|
|
|
|
|
106 |
# Process the audio data as needed
|
107 |
# For this example, we'll just return some basic information
|
108 |
duration = librosa.get_duration(y=audio, sr=sr)
|
|
|
11 |
import random
|
12 |
import tempfile
|
13 |
import os
|
14 |
+
import numba
|
15 |
+
import soundfile as sf
|
16 |
+
|
17 |
+
os.environ['NUMBA_DISABLE_INTEL_SVML'] = '1'
|
18 |
+
os.environ['LIBROSA_CACHE_DIR'] = '/tmp/librosa_cache'
|
19 |
+
os.environ['NUMBA_CACHE_DIR'] = '/tmp/numba_cache'
|
20 |
+
|
21 |
+
numba.config.DISABLE_JIT = True
|
22 |
|
|
|
23 |
MultiPartParser.max_file_size = 200 * 1024 * 1024
|
24 |
|
25 |
# Initialize FastAPI app
|
|
|
108 |
print("Uploaded file saved to:", temp_file_path)
|
109 |
|
110 |
# Load the audio file using librosa with a fixed sample rate of 16000 Hz
|
111 |
+
audio, sr = sf.read(temp_file_path)
|
112 |
+
if sr != 16000:
|
113 |
+
# Resample if necessary
|
114 |
+
audio = librosa.resample(audio, sr, 16000)
|
115 |
+
sr = 16000
|
116 |
# Process the audio data as needed
|
117 |
# For this example, we'll just return some basic information
|
118 |
duration = librosa.get_duration(y=audio, sr=sr)
|