JBHF commited on
Commit
b941138
1 Parent(s): c2e6e86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -75,6 +75,15 @@ st.title("Audio Recorder")
75
  # audiorecorder(start_prompt="Start recording", stop_prompt="Stop recording", pause_prompt="", key=None):
76
  audio = audiorecorder("Click to record", "Click to stop recording", "Click to pause recording")
77
 
 
 
 
 
 
 
 
 
 
78
  if len(audio) > 0:
79
  # To play audio in frontend:
80
  st.audio(audio.export().read())
@@ -82,8 +91,9 @@ if len(audio) > 0:
82
  # To save audio to a file, use pydub export method:
83
  # https://docs.streamlit.io/develop/concepts/architecture/caching
84
  # @st.cache_data
85
- @st.cache_data
86
- audio.export("audio.wav", format="wav")
 
87
 
88
  # To get audio properties, use pydub AudioSegment properties:
89
  st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")
 
75
  # audiorecorder(start_prompt="Start recording", stop_prompt="Stop recording", pause_prompt="", key=None):
76
  audio = audiorecorder("Click to record", "Click to stop recording", "Click to pause recording")
77
 
78
+
79
+ # JB:
80
+ # https://docs.streamlit.io/develop/concepts/architecture/caching
81
+ # @st.cache_data
82
+ @st.cache_data
83
+ def audio_export(audio_wav_file, format):
84
+ # audio.export("audio.wav", format="wav") # ORIGINAL
85
+ audio.export(audio_wav_file, format=format)
86
+
87
  if len(audio) > 0:
88
  # To play audio in frontend:
89
  st.audio(audio.export().read())
 
91
  # To save audio to a file, use pydub export method:
92
  # https://docs.streamlit.io/develop/concepts/architecture/caching
93
  # @st.cache_data
94
+ # @st.cache_data
95
+ # audio.export("audio.wav", format="wav") # ORIGINAL
96
+ audio_export("audio.wav", format="wav") # JB 08-04-2024
97
 
98
  # To get audio properties, use pydub AudioSegment properties:
99
  st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")