Mohammedallyl commited on
Commit
bb780d8
·
verified ·
1 Parent(s): 564a229

Update Logic/SpeachToText.py

Browse files
Files changed (1) hide show
  1. 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
- environ["GOOGLE_APPLICATION_CREDENTIALS"]="smms"
15
- Text:str=Recognizer.recognize_google(audio,language="en-US")
16
-
17
- if ("on" in Text and "light" in Text) or ("off" not in Text and "light" in Text):
18
- return {"Status":True,"Message":"l"} # l ::LightOn
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}