Spaces:
Running
Running
Update speech_api.py
Browse files- speech_api.py +7 -2
speech_api.py
CHANGED
@@ -61,6 +61,11 @@ async def speech_to_text(file: UploadFile = File(...), source_language: str = "m
|
|
61 |
audio_content = await file.read()
|
62 |
asr_result = client.asr(audio_content, source_language=source_language)
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
65 |
except Exception as e:
|
66 |
-
raise HTTPException(status_code=500, detail=str(e))
|
|
|
61 |
audio_content = await file.read()
|
62 |
asr_result = client.asr(audio_content, source_language=source_language)
|
63 |
|
64 |
+
# Extract the transcribed text from the complex JSON structure
|
65 |
+
transcribed_text = asr_result['transcription']['pipelineResponse'][0]['output'][0]['source']
|
66 |
+
|
67 |
+
return {"text": transcribed_text}
|
68 |
+
except KeyError:
|
69 |
+
raise HTTPException(status_code=500, detail="Unexpected response structure from ASR service")
|
70 |
except Exception as e:
|
71 |
+
raise HTTPException(status_code=500, detail=str(e))
|