awacke1 commited on
Commit
9b9483a
·
1 Parent(s): 576e642

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -70,29 +70,24 @@ def transcribe_audio(openai_key, file_path, model):
70
  st.write(response.json())
71
  st.error("Error in API call.")
72
  return None
73
-
74
- def save_and_play_audio(audio_recorder):
75
- col1 = st.sidebar.columns([1]) # adjust the ratio as needed
76
- with col1:
77
- try:
78
- audio_bytes = audio_recorder()
79
- if audio_bytes:
80
- filename = generate_filename("Recording", "wav")
81
- with open(filename, 'wb') as f:
82
- f.write(audio_bytes)
83
- st.audio(audio_bytes, format="audio/wav")
84
- return filename
85
- except Exception as e:
86
- st.error(f"Error occurred while processing audio recording")
87
- return None
88
 
 
 
 
 
 
 
 
 
89
  # Updated to call direct from transcription to chat inference.
90
- filename = save_and_play_audio(audio_recorder)
91
- if filename is not None:
92
- #if st.button("Transcribe"):
93
- transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
94
- st.markdown('### Transcription:')
95
- st.write(transcription)
 
 
96
 
97
  def truncate_document(document, length):
98
  return document[:length]
 
70
  st.write(response.json())
71
  st.error("Error in API call.")
72
  return None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ def save_and_play_audio(audio_recorder):
75
+ audio_bytes = st.sidebar.audio_recorder()
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
  # Updated to call direct from transcription to chat inference.
83
+ USEAUDIO=False
84
+ if USEAUDIO:
85
+ filename = save_and_play_audio(audio_recorder)
86
+ if filename is not None:
87
+ #if st.button("Transcribe"):
88
+ transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
89
+ st.markdown('### Transcription:')
90
+ st.write(transcription)
91
 
92
  def truncate_document(document, length):
93
  return document[:length]