Spaces:
Sleeping
Sleeping
First project structure
Browse files- .gitignore +3 -0
- app/main.py +48 -0
- requirements.txt +9 -0
- safetycam/__init__.py +0 -0
.gitignore
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# files meant to exist locally only
|
2 |
+
env/
|
3 |
+
scratch/
|
app/main.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_webrtc import webrtc_streamer
|
3 |
+
import speech_recognition as sr
|
4 |
+
import time
|
5 |
+
|
6 |
+
def speech_to_text_microphone():
|
7 |
+
# initialize recognizer class (for recognizing the speech)
|
8 |
+
r = sr.Recognizer()
|
9 |
+
|
10 |
+
# Reading Microphone as source
|
11 |
+
# listening the speech and store in audio_text variable
|
12 |
+
with sr.Microphone() as source:
|
13 |
+
audio_text = r.listen(source)
|
14 |
+
# recoginize_() method will throw a request error if the API is unreachable, hence using exception handling
|
15 |
+
try:
|
16 |
+
# using google speech recognition
|
17 |
+
return r.recognize_google(audio_text)
|
18 |
+
except:
|
19 |
+
return ""
|
20 |
+
|
21 |
+
|
22 |
+
audio = ""
|
23 |
+
st.title("SafetyCam")
|
24 |
+
|
25 |
+
webrtc_streamer(key="video")
|
26 |
+
def live_caption():
|
27 |
+
text = ""
|
28 |
+
# Initialize recognizer and microphone objects
|
29 |
+
r = sr.Recognizer()
|
30 |
+
mic = sr.Microphone()
|
31 |
+
|
32 |
+
# Set minimum energy threshold to account for ambient noise
|
33 |
+
with mic as source:
|
34 |
+
r.adjust_for_ambient_noise(source)
|
35 |
+
|
36 |
+
# Continuously listen to microphone input and print live caption
|
37 |
+
with mic as source:
|
38 |
+
while True:
|
39 |
+
try:
|
40 |
+
audio = r.listen(source)
|
41 |
+
text = r.recognize_google(audio)
|
42 |
+
print(text)
|
43 |
+
st.write(text)
|
44 |
+
except sr.UnknownValueError:
|
45 |
+
# Handle unrecognized speech
|
46 |
+
pass
|
47 |
+
if st.button("Start Live Caption"):
|
48 |
+
live_caption()
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
ipykernel>=6.21.3,<=6.22
|
2 |
+
mediapipe>=0.9.1.0,<=0.10
|
3 |
+
numpy>=1.24.2,<=1.25
|
4 |
+
pandas>=1.5.3,<=1.6
|
5 |
+
PyAudio>=0.2.13,<=0.3
|
6 |
+
pydub>=0.25.1,<=0.26
|
7 |
+
SpeechRecognition>=3.10.0,<=3.11
|
8 |
+
streamlit>=1.20.0,<=1.21
|
9 |
+
streamlit-webrtc>=0.45.0,<=0.46
|
safetycam/__init__.py
ADDED
File without changes
|