Spaces:
Runtime error
Runtime error
khairul ichsan
commited on
Commit
•
8197e7c
1
Parent(s):
a04e2af
update files
Browse files
app.py
CHANGED
@@ -1,4 +1,58 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
1 |
+
# streamlit_audio_recorder by stefanrmmr (rs. analytics) - version January 2023
|
2 |
+
|
3 |
import streamlit as st
|
4 |
+
from st_audiorec import st_audiorec
|
5 |
+
|
6 |
+
# DESIGN implement changes to the standard streamlit UI/UX
|
7 |
+
# --> optional, not relevant for the functionality of the component!
|
8 |
+
st.set_page_config(page_title="streamlit_audio_recorder")
|
9 |
+
# Design move app further up and remove top padding
|
10 |
+
st.markdown('''<style>.css-1egvi7u {margin-top: -3rem;}</style>''',
|
11 |
+
unsafe_allow_html=True)
|
12 |
+
# Design change st.Audio to fixed height of 45 pixels
|
13 |
+
st.markdown('''<style>.stAudio {height: 45px;}</style>''',
|
14 |
+
unsafe_allow_html=True)
|
15 |
+
# Design change hyperlink href link color
|
16 |
+
st.markdown('''<style>.css-v37k9u a {color: #ff4c4b;}</style>''',
|
17 |
+
unsafe_allow_html=True) # darkmode
|
18 |
+
st.markdown('''<style>.css-nlntq9 a {color: #ff4c4b;}</style>''',
|
19 |
+
unsafe_allow_html=True) # lightmode
|
20 |
+
|
21 |
+
|
22 |
+
def audiorec_demo_app():
|
23 |
+
|
24 |
+
# TITLE and Creator information
|
25 |
+
st.title('streamlit audio recorder')
|
26 |
+
st.markdown('Implemented by '
|
27 |
+
'[Stefan Rummer](https://www.linkedin.com/in/stefanrmmr/) - '
|
28 |
+
'view project source code on '
|
29 |
+
|
30 |
+
'[GitHub](https://github.com/stefanrmmr/streamlit-audio-recorder)')
|
31 |
+
st.write('\n\n')
|
32 |
+
|
33 |
+
# TUTORIAL: How to use STREAMLIT AUDIO RECORDER?
|
34 |
+
# by calling this function an instance of the audio recorder is created
|
35 |
+
# once a recording is completed, audio data will be saved to wav_audio_data
|
36 |
+
|
37 |
+
wav_audio_data = st_audiorec() # tadaaaa! yes, that's it! :D
|
38 |
+
|
39 |
+
# add some spacing and informative messages
|
40 |
+
col_info, col_space = st.columns([0.57, 0.43])
|
41 |
+
with col_info:
|
42 |
+
st.write('\n') # add vertical spacer
|
43 |
+
st.write('\n') # add vertical spacer
|
44 |
+
st.write('The .wav audio data, as received in the backend Python code,'
|
45 |
+
' will be displayed below this message as soon as it has'
|
46 |
+
' been processed. [This informative message is not part of'
|
47 |
+
' the audio recorder and can be removed easily] 🎈')
|
48 |
+
|
49 |
+
if wav_audio_data is not None:
|
50 |
+
# display audio data as received on the Python side
|
51 |
+
col_playback, col_space = st.columns([0.58,0.42])
|
52 |
+
with col_playback:
|
53 |
+
st.audio(wav_audio_data, format='audio/wav')
|
54 |
+
|
55 |
|
56 |
+
if __name__ == '__main__':
|
57 |
+
# call main function
|
58 |
+
audiorec_demo_app()
|
setup.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
import setuptools
|
3 |
+
|
4 |
+
this_directory = Path(__file__).parent
|
5 |
+
long_description = (this_directory / "README.md").read_text()
|
6 |
+
|
7 |
+
setuptools.setup(
|
8 |
+
name="streamlit-audiorec",
|
9 |
+
version="0.1.3",
|
10 |
+
author="Stefan Rummer",
|
11 |
+
author_email="",
|
12 |
+
description="Record audio from the user's microphone in apps that are deployed to the web. (via Browser Media-API) [GitHub ☆ 160+: steamlit-audio-recorder]",
|
13 |
+
long_description=long_description,
|
14 |
+
long_description_content_type="text/markdown",
|
15 |
+
url="https://github.com/stefanrmmr/streamlit-audio-recorder",
|
16 |
+
packages=setuptools.find_packages(),
|
17 |
+
include_package_data=True,
|
18 |
+
classifiers=[],
|
19 |
+
python_requires=">=3.7",
|
20 |
+
install_requires=[
|
21 |
+
"streamlit>=0.63",
|
22 |
+
],
|
23 |
+
)
|