rahulramar commited on
Commit
656745e
1 Parent(s): c738d55

first commit

Browse files
Files changed (2) hide show
  1. app.py +67 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import cv2
3
+ from streamlit_webrtc import WebRtcMode,RTCConfiguration, VideoTransformerBase, webrtc_streamer, AudioProcessorBase
4
+ from DistanceEstimation import *
5
+ from typing import Awaitable, Callable, Generic, List, Optional, TypeVar
6
+ import streamlit as st
7
+ from streamlit_autorefresh import st_autorefresh
8
+ import time
9
+
10
+ audio_counter = 0
11
+ new_audio_file = open('audio.mp3', 'rb')
12
+ audio_bytes = new_audio_file.read()
13
+ new_audio_file.close()
14
+ st.audio(audio_bytes, format='audio/ogg')
15
+ RTC_CONFIGURATION = RTCConfiguration(
16
+ {"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}
17
+ )
18
+
19
+ count = st_autorefresh(interval=4500, limit=1000000, key="fizzbuzzcounter")
20
+
21
+ import av
22
+ from tts import *
23
+
24
+
25
+
26
+ class VideoTransformer(VideoTransformerBase):
27
+ def __init__(self) -> None:
28
+ super().__init__()
29
+ self.frame_count = 0
30
+
31
+
32
+ def transform(self, frame):
33
+ img = frame.to_ndarray(format="bgr24")
34
+ new_img = get_frame_output(img, self.frame_count)
35
+ return new_img
36
+
37
+ # input - webcam video => transform() => final output arrived(retured to browser)
38
+ def recv(self, frame: av.VideoFrame) -> av.VideoFrame:
39
+ new_image = self.transform(frame)
40
+
41
+ return av.VideoFrame.from_ndarray(new_image, format="bgr24")
42
+
43
+ class AudioProcessor(AudioProcessorBase):
44
+
45
+ def reset_audio(self):
46
+ time.sleep(0.1)
47
+ self.new_audio_file = open('audio.mp3', 'rb')
48
+ self.audio_bytes = self.new_audio_file.read()
49
+ print(len(self.audio_bytes))
50
+ self.new_audio_file.close()
51
+ st.audio(self.audio_bytes, format='audio/ogg')
52
+
53
+
54
+ async def recv_queued(self, frames: List[av.AudioFrame]) -> List[av.AudioFrame]:
55
+ get_audio() #tts happens
56
+ self.reset_audio() # for UI updation
57
+ return []
58
+
59
+ if __name__ == "__main__":
60
+ # webrtc_streamer(key="example", video_processor_factory=VideoTransformer)
61
+ webrtc_streamer( key="WYH",
62
+ mode=WebRtcMode.SENDRECV,
63
+ rtc_configuration=RTC_CONFIGURATION,
64
+ media_stream_constraints={"video": True, "audio": True},
65
+ video_processor_factory=VideoTransformer,
66
+ audio_processor_factory=AudioProcessor,
67
+ )
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ av==9.2.0
2
+ ibm_cloud_sdk_core==3.15.3
3
+ ibm_watson==6.0.0
4
+ numpy==1.22.4
5
+ opencv-python-headless==4.5.5.64
6
+ streamlit
7
+ streamlit_autorefresh
8
+ streamlit_webrtc