jdalfonso commited on
Commit
da5b41d
·
1 Parent(s): eba662e

:rocket: feature: realtime audio

Browse files
Files changed (1) hide show
  1. views/application.py +12 -8
views/application.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
  import datetime
3
  import os
4
 
@@ -17,24 +18,27 @@ def application():
17
 
18
  st.markdown("---")
19
 
20
- tab1, tab2 = st.tabs(["Record Audio", "Register Audio"])
21
 
22
  with tab1:
23
- st.header("Record Audio")
24
  st.write("Here you can record audio.")
25
  audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
26
  if audio_file is not None:
27
 
28
- with open(f"audios/{FILE_NAME}", "wb") as f:
29
  f.write(audio_file.getbuffer())
30
  st.success(f"Saved file: {FILE_NAME}")
31
 
32
  with tab2:
33
- st.header("Register Audio")
34
  st.write("Here you can register audio.")
35
 
 
 
36
 
37
- file = os.path.join(DIRECTORY, FILE_NAME)
38
- if os.path.exists(file):
39
- st.markdown("## File registered:")
40
- audio_data = st.audio(file, format='audio/wav', start_time=0)
 
 
1
  import streamlit as st
2
+ from st_audiorec import st_audiorec
3
  import datetime
4
  import os
5
 
 
18
 
19
  st.markdown("---")
20
 
21
+ tab1, tab2 = st.tabs(["⬆️ Record Audio", "🔈 Register Audio"])
22
 
23
  with tab1:
24
+ st.header("⬆️ Upload Audio")
25
  st.write("Here you can record audio.")
26
  audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
27
  if audio_file is not None:
28
 
29
+ with open(f"{DIRECTORY}/{FILE_NAME}", "wb") as f:
30
  f.write(audio_file.getbuffer())
31
  st.success(f"Saved file: {FILE_NAME}")
32
 
33
  with tab2:
34
+ st.header("🔈 Realtime Audio")
35
  st.write("Here you can register audio.")
36
 
37
+ if st.button("Register", key="register-button"):
38
+ st.success("Audio registered successfully.")
39
 
40
+ wav_audio_data = st_audiorec()
41
+
42
+ if wav_audio_data is not None:
43
+ st.audio(wav_audio_data, format='audio/wav')
44
+