d3dname commited on
Commit
455b687
·
verified ·
1 Parent(s): eedecde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -159,24 +159,31 @@ with right:
159
  st.markdown('''<h3><i class="fa fa-pencil"></i> Form 2</h3>''', unsafe_allow_html=True)
160
 
161
  # Box 3: Form 2
162
- uploaded_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "flac", "aac"])
163
- microphone_input = st.audio("Record audio using microphone", format="audio/wav")
 
 
 
 
 
 
 
 
 
164
  if st.button("Transcribe"):
165
- if microphone_input and uploaded_file:
166
- st.warning("WARNING: You've uploaded an audio file and used the microphone. The recorded file from the microphone will be used, and the uploaded audio will be discarded.")
167
- file_to_transcribe = microphone_input
168
- elif microphone_input:
169
- file_to_transcribe = microphone_input
170
- elif uploaded_file:
171
- file_to_transcribe = uploaded_file
172
- else:
173
- st.error("ERROR: You have to either use the microphone or upload an audio file")
174
- file_to_transcribe = None
175
-
176
- if file_to_transcribe:
177
  with st.spinner("Transcribing..."):
178
- transcription = transcribe(file_to_transcribe)
179
- st.write(transcription)
 
 
 
 
 
 
180
 
181
  # End of Box 3 and third Carousel Item
182
  st.markdown('''<h3><i class="fa fa-pencil"></i> Form 3</h3>''', unsafe_allow_html=True)
 
159
  st.markdown('''<h3><i class="fa fa-pencil"></i> Form 2</h3>''', unsafe_allow_html=True)
160
 
161
  # Box 3: Form 2
162
+ # Audio recording using mic_recorder
163
+ audio = mic_recorder(
164
+ start_prompt="Start recording",
165
+ stop_prompt="Stop recording",
166
+ just_once=False,
167
+ use_container_width=False,
168
+ callback=None,
169
+ key="mic_recorder"
170
+ )
171
+
172
+ uploaded_file = st.file_uploader("Or upload an audio file", type=["mp3", "wav", "flac", "aac"])
173
  if st.button("Transcribe"):
174
+ if audio:
175
+ st.success("Recording detected. Transcribing your recording...")
176
+ with open("temp_recording.wav", "wb") as f:
177
+ f.write(audio)
 
 
 
 
 
 
 
 
178
  with st.spinner("Transcribing..."):
179
+ transcription = transcribe("temp_recording.wav")
180
+ st.text_area("Transcription", transcription, height=200)
181
+ elif uploaded_file is not None:
182
+ with st.spinner("Transcribing..."):
183
+ transcription = transcribe(uploaded_file)
184
+ st.text_area("Transcription", transcription, height=200)
185
+ else:
186
+ st.error("Please record audio or upload a file to transcribe.")
187
 
188
  # End of Box 3 and third Carousel Item
189
  st.markdown('''<h3><i class="fa fa-pencil"></i> Form 3</h3>''', unsafe_allow_html=True)