Spaces:
Sleeping
Sleeping
Update Logic/SpeachToText.py
Browse files- Logic/SpeachToText.py +3 -3
Logic/SpeachToText.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from fastapi import
|
2 |
from fastapi.responses import JSONResponse
|
3 |
from pydantic import BaseModel
|
4 |
import speech_recognition as sr
|
@@ -6,12 +6,12 @@ from io import BytesIO
|
|
6 |
from pydub import AudioSegment
|
7 |
import os
|
8 |
|
9 |
-
|
10 |
|
11 |
class TranscriptionResponse(BaseModel):
|
12 |
text: str
|
13 |
|
14 |
-
@
|
15 |
async def transcribe_audio(file: UploadFile = File(...)):
|
16 |
if file.content_type not in ["audio/wav", "audio/mpeg", "audio/mp3", "audio/x-wav", "audio/flac"]:
|
17 |
raise HTTPException(status_code=400, detail="Unsupported file type")
|
|
|
1 |
+
from fastapi import APIRouter, File, UploadFile, HTTPException
|
2 |
from fastapi.responses import JSONResponse
|
3 |
from pydantic import BaseModel
|
4 |
import speech_recognition as sr
|
|
|
6 |
from pydub import AudioSegment
|
7 |
import os
|
8 |
|
9 |
+
SpeachRouter = APIRouter()
|
10 |
|
11 |
class TranscriptionResponse(BaseModel):
|
12 |
text: str
|
13 |
|
14 |
+
@SpeachRouter.post("/SpeechToText", response_model=TranscriptionResponse)
|
15 |
async def transcribe_audio(file: UploadFile = File(...)):
|
16 |
if file.content_type not in ["audio/wav", "audio/mpeg", "audio/mp3", "audio/x-wav", "audio/flac"]:
|
17 |
raise HTTPException(status_code=400, detail="Unsupported file type")
|