Spaces:
Sleeping
Sleeping
Update Logic/SpeachToText.py
Browse files- Logic/SpeachToText.py +18 -23
Logic/SpeachToText.py
CHANGED
|
@@ -1,24 +1,19 @@
|
|
| 1 |
-
from fastapi import APIRouter,UploadFile
|
| 2 |
-
from io import BytesIO
|
| 3 |
-
import speech_recognition as sr
|
| 4 |
-
from scipy.io import wavfile
|
| 5 |
-
from os import environ
|
| 6 |
-
Recognizer=sr.Recognizer()
|
| 7 |
-
SpeachRouter=APIRouter()
|
| 8 |
-
@SpeachRouter.post("/SpeachTotext")
|
| 9 |
-
def SpeachToTextEndPoint(Audio:UploadFile):
|
| 10 |
-
try:
|
| 11 |
-
with sr.AudioFile(BytesIO(Audio.file.read())) as File:
|
| 12 |
-
|
| 13 |
-
audio=Recognizer.listen(File)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
elif "light" in Text:
|
| 20 |
-
return {"Status":True,"Message":"o"} # o ::LightOff
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
except LookupError as e:
|
| 24 |
return {"Status":False,"Message":e}
|
|
|
|
| 1 |
+
from fastapi import APIRouter,UploadFile
|
| 2 |
+
from io import BytesIO
|
| 3 |
+
import speech_recognition as sr
|
| 4 |
+
from scipy.io import wavfile
|
| 5 |
+
from os import environ
|
| 6 |
+
Recognizer=sr.Recognizer()
|
| 7 |
+
SpeachRouter=APIRouter()
|
| 8 |
+
@SpeachRouter.post("/SpeachTotext")
|
| 9 |
+
def SpeachToTextEndPoint(Audio:UploadFile):
|
| 10 |
+
try:
|
| 11 |
+
with sr.AudioFile(BytesIO(Audio.file.read())) as File:
|
| 12 |
+
|
| 13 |
+
audio=Recognizer.listen(File)
|
| 14 |
+
Text:str=Recognizer.recognize_google(audio,language="en-US")
|
| 15 |
+
return { Status":True,"Message":Text}
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
except LookupError as e:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
return {"Status":False,"Message":e}
|