awacke1 commited on
Commit
c3cef0a
·
1 Parent(s): 467a294

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -23,11 +23,26 @@ menu = ["txt", "htm", "md", "py"]
23
  choice = st.sidebar.selectbox("Output File Type:", menu)
24
  model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
25
 
26
- audio_bytes = audio_recorder()
27
- if audio_bytes:
28
- st.audio(audio_bytes, format="audio/wav")
29
 
30
- def transcribe_audio_ui(openai_key):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  OPENAI_API_KEY = openai_key
32
  OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
33
 
 
23
  choice = st.sidebar.selectbox("Output File Type:", menu)
24
  model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
25
 
 
 
 
26
 
27
+ def save_and_play_audio(audio_recorder, st):
28
+ audio_bytes = audio_recorder()
29
+ if audio_bytes:
30
+ now = datetime.datetime.now()
31
+ filename = f"audio_{now.strftime('%Y%m%d_%H%M%S')}.wav"
32
+ with open(filename, 'wb') as f:
33
+ f.write(audio_bytes)
34
+ st.audio(audio_bytes, format="audio/wav")
35
+ return filename
36
+ return None
37
+
38
+ filename = save_and_play_audio(audio_recorder, st)
39
+ if filename:
40
+ st.write(f"Audio file has been saved as {filename}")
41
+ else:
42
+ st.write("No audio data was recorded")
43
+
44
+
45
+ def transcribe_audio_ui(openai_key, file_path):
46
  OPENAI_API_KEY = openai_key
47
  OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
48