Spaces:
Sleeping
Sleeping
File size: 899 Bytes
c4dc0b3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from fastapi import APIRouter,UploadFile
from io import BytesIO
import speech_recognition as sr
from scipy.io import wavfile
from os import environ
Recognizer=sr.Recognizer()
SpeachRouter=APIRouter()
@SpeachRouter.post("/SpeachTotext")
def SpeachToTextEndPoint(Audio:UploadFile):
try:
with sr.AudioFile(BytesIO(Audio.file.read())) as File:
audio=Recognizer.listen(File)
environ["GOOGLE_APPLICATION_CREDENTIALS"]="smms"
Text:str=Recognizer.recognize_google(audio,language="en-US")
if ("on" in Text and "light" in Text) or ("off" not in Text and "light" in Text):
return {"Status":True,"Message":"l"} # l ::LightOn
elif "light" in Text:
return {"Status":True,"Message":"o"} # o ::LightOff
except LookupError as e:
return {"Status":False,"Message":e} |