Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -71,23 +71,26 @@ def transcribe_audio(openai_key, file_path, model):
|
|
71 |
st.error("Error in API call.")
|
72 |
return None
|
73 |
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
if audio_bytes:
|
77 |
filename = generate_filename("Recording", "wav")
|
78 |
with open(filename, 'wb') as f:
|
79 |
f.write(audio_bytes)
|
80 |
st.audio(audio_bytes, format="audio/wav")
|
81 |
return filename
|
82 |
-
|
83 |
-
USEAUDIO=False
|
84 |
if USEAUDIO:
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
|
92 |
def truncate_document(document, length):
|
93 |
return document[:length]
|
|
|
71 |
st.error("Error in API call.")
|
72 |
return None
|
73 |
|
74 |
+
|
75 |
+
# Updated to call direct from transcription to chat inference.
|
76 |
+
save_and_play_audio(audio_recorder):
|
77 |
+
audio_bytes = audio_recorder()
|
78 |
if audio_bytes:
|
79 |
filename = generate_filename("Recording", "wav")
|
80 |
with open(filename, 'wb') as f:
|
81 |
f.write(audio_bytes)
|
82 |
st.audio(audio_bytes, format="audio/wav")
|
83 |
return filename
|
84 |
+
USEAUDIO=True
|
|
|
85 |
if USEAUDIO:
|
86 |
+
if st.sidebar.checkbox('Use Audio Input'):
|
87 |
+
filename = save_and_play_audio(audio_recorder)
|
88 |
+
if filename is not None:
|
89 |
+
#if st.button("Transcribe"):
|
90 |
+
transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
|
91 |
+
st.markdown('### Transcription:')
|
92 |
+
st.write(transcription)
|
93 |
+
|
94 |
|
95 |
def truncate_document(document, length):
|
96 |
return document[:length]
|