Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,11 +37,14 @@ async def transcribe_audio(request: AudioRequest):
|
|
| 37 |
try:
|
| 38 |
audio_bytes = base64.b64decode(request.audio)
|
| 39 |
audio_array, sample_rate = sf.read(io.BytesIO(audio_bytes))
|
| 40 |
-
|
| 41 |
# Convert to mono if stereo
|
| 42 |
if len(audio_array.shape) > 1:
|
| 43 |
audio_array = audio_array.mean(axis=1)
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
result = transcribe(audio_array, request.language)
|
| 46 |
return JSONResponse(content={"transcription": result})
|
| 47 |
except Exception as e:
|
|
|
|
| 37 |
try:
|
| 38 |
audio_bytes = base64.b64decode(request.audio)
|
| 39 |
audio_array, sample_rate = sf.read(io.BytesIO(audio_bytes))
|
|
|
|
| 40 |
# Convert to mono if stereo
|
| 41 |
if len(audio_array.shape) > 1:
|
| 42 |
audio_array = audio_array.mean(axis=1)
|
| 43 |
+
# Ensure audio_array is float32
|
| 44 |
+
audio_array = audio_array.astype(np.float32)
|
| 45 |
+
# Resample if necessary
|
| 46 |
+
if sample_rate != ASR_SAMPLING_RATE:
|
| 47 |
+
audio_array = librosa.resample(audio_array, orig_sr=sample_rate, target_sr=ASR_SAMPLING_RATE)
|
| 48 |
result = transcribe(audio_array, request.language)
|
| 49 |
return JSONResponse(content={"transcription": result})
|
| 50 |
except Exception as e:
|