JBHF commited on
Commit
66012c7
1 Parent(s): a4023d4

app-26-03-2024.py

Browse files
Files changed (1) hide show
  1. app-26-03-2024.py +48 -0
app-26-03-2024.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # JBHF/VERTAAL-APP-EAGLE-SHELTER/app.py - 26-03-2024
2
+
3
+ # https://github.com/theevann/streamlit-audiorecorder
4
+ # An audio Recorder for streamlit
5
+ #
6
+ # Description
7
+ # Audio recorder component for streamlit.
8
+ # It creates a button to start the recording and takes three arguments:
9
+ # the start button text, the stop button text, and the pause button text.
10
+ # If the pause button text is not specified, the pause button is not displayed.
11
+ #
12
+ # Parameters
13
+ # The signature of the component is:
14
+ # audiorecorder(start_prompt="Start recording", stop_prompt="Stop recording", pause_prompt="", key=None):
15
+ # The prompt parameters are self-explanatory, and the optional key parameter is used internally by streamlit
16
+ # to properly distinguish multiple audiorecorders on the page.
17
+ #
18
+ # Return value
19
+ # The component's return value is a pydub AudioSegment.
20
+ #
21
+ # All AudioSegment methods are available, in particular you can:
22
+ # - Play the audio in the frontend with st.audio(audio.export().read())
23
+ # - Save the audio to a file with audio.export("audio.wav", format="wav")
24
+ # JB: Waarom zie ik in mijn HF Spaces omgeving de file "audio.wav" niet terug ?
25
+ #
26
+ # Installation:
27
+ # pip install streamlit-audiorecorder
28
+ # Note: This package uses ffmpeg, so it should be installed for this audiorecorder to work properly.
29
+ #
30
+ # On ubuntu/debian: sudo apt update && sudo apt install ffmpeg
31
+ # On mac: brew install ffmpeg
32
+
33
+ import streamlit as st
34
+ from audiorecorder import audiorecorder
35
+
36
+ st.title("Audio Recorder")
37
+ # audiorecorder(start_prompt="Start recording", stop_prompt="Stop recording", pause_prompt="", key=None):
38
+ audio = audiorecorder("Click to record", "Click to stop recording", "Click to pause recording")
39
+
40
+ if len(audio) > 0:
41
+ # To play audio in frontend:
42
+ st.audio(audio.export().read())
43
+
44
+ # To save audio to a file, use pydub export method:
45
+ audio.export("audio.wav", format="wav")
46
+
47
+ # To get audio properties, use pydub AudioSegment properties:
48
+ st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")