awacke1 commited on
Commit
08c27ff
Β·
verified Β·
1 Parent(s): e1b0ca6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -36
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import pandas as pd
3
  from datetime import datetime
4
  import cv2
5
- import pyaudio
6
  import wave
7
  import imageio
8
  import av
@@ -34,7 +34,7 @@ st.title("πŸ“ΈπŸŽ™οΈ Capture Craze")
34
  # πŸŽ›οΈ Sidebar config like a spaceship control panel!
35
  with st.sidebar:
36
  st.header("πŸŽšοΈπŸ“Έ Tune-Up Zone")
37
- library_choice = st.selectbox("πŸ“š Pick a Tool", ["OpenCV", "PyAudio", "ImageIO", "PyAV", "MoviePy"])
38
  resolution = st.select_slider("πŸ“ Snap Size", options=["320x240", "640x480", "1280x720"], value="640x480")
39
  fps = st.slider("⏱️ Speed Snap", 1, 60, 30)
40
 
@@ -98,47 +98,41 @@ with st.expander("1️⃣ πŸ“· OpenCV Fiesta"):
98
  st.image(file_path, caption="πŸ” Edge Lord")
99
  cap.release()
100
 
101
- # 2. PyAudio - πŸŽ™οΈ Soundwave showdown!
102
- with st.expander("2️⃣ πŸŽ™οΈ PyAudio Party"):
103
  st.write("πŸ”Š Audio Ace: Sound control ninja!")
104
  st.subheader("πŸ”₯ Top Tricks")
105
 
106
  st.write("🎀🌩️ Record Jam")
107
- if st.button("🎡 Grab Sound", key="pyaudio_1"):
108
- # 🎀🌩️ Records like a storm-chasing bard! | πŸŽ™οΈ stream = pyaudio.PyAudio().open(...) - Captures audio like thunder in a bottle!
109
- p = pyaudio.PyAudio()
110
- stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
111
- frames = [stream.read(1024) for _ in range(int(44100 / 1024 * 3))]
112
- stream.stop_stream()
113
- stream.close()
114
- p.terminate()
115
- file_path = f"pyaudio_rec_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
116
  with wave.open(file_path, 'wb') as wf:
117
  wf.setnchannels(1)
118
- wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))
119
- wf.setframerate(44100)
120
- wf.writeframes(b''.join(frames))
121
  save_to_history("Audio", file_path)
122
  st.audio(file_path)
123
 
124
- st.write("πŸ•΅οΈβ€β™€οΈπŸ“‘ Mic Spy")
125
- if st.button("πŸ” List Mics", key="pyaudio_2"):
126
- # πŸ•΅οΈβ€β™€οΈπŸ“‘ Spies mics like a gossip queen! | πŸ“‘ info = pyaudio.PyAudio().get_device_info_by_index(0) - Sniffs out devices like a tech bloodhound!
127
- p = pyaudio.PyAudio()
128
- devices = [p.get_device_info_by_index(i) for i in range(p.get_device_count())]
129
- st.write("πŸŽ™οΈ Mic Squad:", devices)
130
- p.terminate()
131
 
132
- st.write("πŸŽΆπŸ’Ύ Sound Bite")
133
- if st.button("🎧 Quick Grab", key="pyaudio_3"):
134
- # πŸŽΆπŸ’Ύ Snags audio like a DJ mid-set! | 🎡 data = stream.read(1024) - Bites sound faster than a snack attack!
135
- p = pyaudio.PyAudio()
136
- stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
137
- data = stream.read(1024)
138
- st.write("🎡 Bytes Nabbed:", len(data))
139
- stream.stop_stream()
140
- stream.close()
141
- p.terminate()
142
 
143
  # 3. ImageIO - πŸ–ΌοΈ Pixel playtime!
144
  with st.expander("3️⃣ πŸ“Ή ImageIO Bash"):
@@ -248,9 +242,8 @@ with st.expander("5️⃣ πŸ“Ό MoviePy Gala"):
248
  cap.release()
249
  file_path = f"moviepy_seq_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
250
  clip = mp.ImageSequenceClip(frames, fps=15)
251
- clip.write - init_block_and_save_video_file(file_path)
252
- save_to_history("VideoΨ―ΫŒΩ† st.session_state['file_history'].append({"Timestamp": timestamp, "Type": "Video", "Path": file_path})
253
- st.session_state['file_history'].append({"Timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "Type": "Video", "Path": file_path})
254
  st.video(file_path)
255
 
256
  st.write("πŸ“πŸ‘‘ Size Snap")
 
2
  import pandas as pd
3
  from datetime import datetime
4
  import cv2
5
+ import sounddevice as sd
6
  import wave
7
  import imageio
8
  import av
 
34
  # πŸŽ›οΈ Sidebar config like a spaceship control panel!
35
  with st.sidebar:
36
  st.header("πŸŽšοΈπŸ“Έ Tune-Up Zone")
37
+ library_choice = st.selectbox("πŸ“š Pick a Tool", ["OpenCV", "SoundDevice", "ImageIO", "PyAV", "MoviePy"])
38
  resolution = st.select_slider("πŸ“ Snap Size", options=["320x240", "640x480", "1280x720"], value="640x480")
39
  fps = st.slider("⏱️ Speed Snap", 1, 60, 30)
40
 
 
98
  st.image(file_path, caption="πŸ” Edge Lord")
99
  cap.release()
100
 
101
+ # 2. SoundDevice - πŸŽ™οΈ Soundwave showdown!
102
+ with st.expander("2️⃣ πŸŽ™οΈ SoundDevice Party"):
103
  st.write("πŸ”Š Audio Ace: Sound control ninja!")
104
  st.subheader("πŸ”₯ Top Tricks")
105
 
106
  st.write("🎀🌩️ Record Jam")
107
+ if st.button("🎡 Grab Sound", key="sounddevice_1"):
108
+ # 🎀🌩️ Records like a storm-chasing bard! | πŸŽ™οΈ sd.rec(44100) - Captures audio like thunder in a bottle!
109
+ fs = 44100
110
+ duration = 3 # seconds
111
+ recording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16')
112
+ sd.wait()
113
+ file_path = f"sounddevice_rec_{datetime.now().strftime('%Y%m%d_%H%M%S')}.wav"
 
 
114
  with wave.open(file_path, 'wb') as wf:
115
  wf.setnchannels(1)
116
+ wf.setsampwidth(2) # 16-bit
117
+ wf.setframerate(fs)
118
+ wf.writeframes(recording.tobytes())
119
  save_to_history("Audio", file_path)
120
  st.audio(file_path)
121
 
122
+ st.write("πŸ”ŠπŸ“‘ Device Spy")
123
+ if st.button("πŸ” List Gear", key="sounddevice_2"):
124
+ # πŸ”ŠπŸ“‘ Spies audio gear like a tech sleuth! | πŸ“‘ sd.query_devices() - Sniffs out sound toys like a pro!
125
+ devices = sd.query_devices()
126
+ st.write("πŸŽ™οΈ Gear Squad:", devices)
 
 
127
 
128
+ st.write("πŸŽΆπŸ’Ύ Play Blast")
129
+ if st.button("🎧 Quick Play", key="sounddevice_3"):
130
+ # πŸŽΆπŸ’Ύ Blasts tunes faster than a DJ remix! | 🎡 sd.play(data) - Drops beats like a party bomb!
131
+ fs = 44100
132
+ duration = 1
133
+ data = np.random.uniform(-1, 1, int(fs * duration)).astype(np.float32)
134
+ sd.play(data, fs)
135
+ st.write("🎡 Played a funky noise!")
 
 
136
 
137
  # 3. ImageIO - πŸ–ΌοΈ Pixel playtime!
138
  with st.expander("3️⃣ πŸ“Ή ImageIO Bash"):
 
242
  cap.release()
243
  file_path = f"moviepy_seq_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
244
  clip = mp.ImageSequenceClip(frames, fps=15)
245
+ clip.write_videofile(file_path)
246
+ save_to_history("Video", file_path)
 
247
  st.video(file_path)
248
 
249
  st.write("πŸ“πŸ‘‘ Size Snap")