-
Notifications
You must be signed in to change notification settings - Fork 83
/
demo.py
58 lines (46 loc) · 2.32 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# streamlit_audio_recorder by stefanrmmr (rs. analytics) - version January 2023
import streamlit as st
from st_audiorec import st_audiorec
# DESIGN implement changes to the standard streamlit UI/UX
# --> optional, not relevant for the functionality of the component!
st.set_page_config(page_title="streamlit_audio_recorder")
# Design move app further up and remove top padding
st.markdown('''<style>.css-1egvi7u {margin-top: -3rem;}</style>''',
unsafe_allow_html=True)
# Design change st.Audio to fixed height of 45 pixels
st.markdown('''<style>.stAudio {height: 45px;}</style>''',
unsafe_allow_html=True)
# Design change hyperlink href link color
st.markdown('''<style>.css-v37k9u a {color: #ff4c4b;}</style>''',
unsafe_allow_html=True) # darkmode
st.markdown('''<style>.css-nlntq9 a {color: #ff4c4b;}</style>''',
unsafe_allow_html=True) # lightmode
def audiorec_demo_app():
# TITLE and Creator information
st.title('streamlit audio recorder')
st.markdown('Implemented by '
'[Stefan Rummer](https://www.linkedin.com/in/stefanrmmr/) - '
'view project source code on '
'[GitHub](https://github.com/stefanrmmr/streamlit-audio-recorder)')
st.write('\n\n')
# TUTORIAL: How to use STREAMLIT AUDIO RECORDER?
# by calling this function an instance of the audio recorder is created
# once a recording is completed, audio data will be saved to wav_audio_data
wav_audio_data = st_audiorec() # tadaaaa! yes, that's it! :D
# add some spacing and informative messages
col_info, col_space = st.columns([0.57, 0.43])
with col_info:
st.write('\n') # add vertical spacer
st.write('\n') # add vertical spacer
st.write('The .wav audio data, as received in the backend Python code,'
' will be displayed below this message as soon as it has'
' been processed. [This informative message is not part of'
' the audio recorder and can be removed easily] 🎈')
if wav_audio_data is not None:
# display audio data as received on the Python side
col_playback, col_space = st.columns([0.58,0.42])
with col_playback:
st.audio(wav_audio_data, format='audio/wav')
if __name__ == '__main__':
# call main function
audiorec_demo_app()