shukdevdatta123 commited on
Commit
98851f3
·
verified ·
1 Parent(s): d857feb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -20
app.py CHANGED
@@ -4,6 +4,7 @@ import speech_recognition as sr
4
  from pydub import AudioSegment
5
  import tempfile
6
  import os
 
7
 
8
  # Function to convert video to audio
9
  def video_to_audio(video_file):
@@ -84,7 +85,11 @@ if tab == "Video":
84
 
85
  # Store transcription and audio file in session state
86
  st.session_state.transcription = transcription
87
- st.session_state.wav_audio_file = wav_audio_file
 
 
 
 
88
 
89
  # Cleanup temporary files
90
  os.remove(tmp_video_path)
@@ -93,8 +98,7 @@ if tab == "Video":
93
  # Check if transcription and audio file are stored in session state
94
  if 'transcription' in st.session_state and 'wav_audio_file' in st.session_state:
95
  # Provide the audio file to the user for download
96
- with open(st.session_state.wav_audio_file, "rb") as audio_file_data:
97
- st.audio(audio_file_data.read(), format='audio/wav')
98
 
99
  # Add download buttons for the transcription and audio
100
  # Downloadable transcription file
@@ -106,13 +110,12 @@ if tab == "Video":
106
  )
107
 
108
  # Downloadable audio file
109
- with open(st.session_state.wav_audio_file, "rb") as audio_file_data:
110
- st.download_button(
111
- label="Download Audio",
112
- data=audio_file_data,
113
- file_name="converted_audio.wav",
114
- mime="audio/wav"
115
- )
116
 
117
  elif tab == "Audio":
118
  # File uploader for audio
@@ -141,7 +144,11 @@ elif tab == "Audio":
141
 
142
  # Store transcription in session state
143
  st.session_state.transcription_audio = transcription
144
- st.session_state.wav_audio_file_audio = wav_audio_file
 
 
 
 
145
 
146
  # Cleanup temporary audio file
147
  os.remove(tmp_audio_path)
@@ -149,8 +156,7 @@ elif tab == "Audio":
149
  # Check if transcription and audio file are stored in session state
150
  if 'transcription_audio' in st.session_state and 'wav_audio_file_audio' in st.session_state:
151
  # Provide the audio file to the user for download
152
- with open(st.session_state.wav_audio_file_audio, "rb") as audio_file_data:
153
- st.audio(audio_file_data.read(), format='audio/wav')
154
 
155
  # Add download buttons for the transcription and audio
156
  # Downloadable transcription file
@@ -162,10 +168,9 @@ elif tab == "Audio":
162
  )
163
 
164
  # Downloadable audio file
165
- with open(st.session_state.wav_audio_file_audio, "rb") as audio_file_data:
166
- st.download_button(
167
- label="Download Audio",
168
- data=audio_file_data,
169
- file_name="converted_audio_audio.wav",
170
- mime="audio/wav"
171
- )
 
4
  from pydub import AudioSegment
5
  import tempfile
6
  import os
7
+ import io
8
 
9
  # Function to convert video to audio
10
  def video_to_audio(video_file):
 
85
 
86
  # Store transcription and audio file in session state
87
  st.session_state.transcription = transcription
88
+
89
+ # Store the audio file as a BytesIO object in memory
90
+ with open(wav_audio_file, "rb") as f:
91
+ audio_data = f.read()
92
+ st.session_state.wav_audio_file = io.BytesIO(audio_data)
93
 
94
  # Cleanup temporary files
95
  os.remove(tmp_video_path)
 
98
  # Check if transcription and audio file are stored in session state
99
  if 'transcription' in st.session_state and 'wav_audio_file' in st.session_state:
100
  # Provide the audio file to the user for download
101
+ st.audio(st.session_state.wav_audio_file, format='audio/wav')
 
102
 
103
  # Add download buttons for the transcription and audio
104
  # Downloadable transcription file
 
110
  )
111
 
112
  # Downloadable audio file
113
+ st.download_button(
114
+ label="Download Audio",
115
+ data=st.session_state.wav_audio_file,
116
+ file_name="converted_audio.wav",
117
+ mime="audio/wav"
118
+ )
 
119
 
120
  elif tab == "Audio":
121
  # File uploader for audio
 
144
 
145
  # Store transcription in session state
146
  st.session_state.transcription_audio = transcription
147
+
148
+ # Store the audio file as a BytesIO object in memory
149
+ with open(wav_audio_file, "rb") as f:
150
+ audio_data = f.read()
151
+ st.session_state.wav_audio_file_audio = io.BytesIO(audio_data)
152
 
153
  # Cleanup temporary audio file
154
  os.remove(tmp_audio_path)
 
156
  # Check if transcription and audio file are stored in session state
157
  if 'transcription_audio' in st.session_state and 'wav_audio_file_audio' in st.session_state:
158
  # Provide the audio file to the user for download
159
+ st.audio(st.session_state.wav_audio_file_audio, format='audio/wav')
 
160
 
161
  # Add download buttons for the transcription and audio
162
  # Downloadable transcription file
 
168
  )
169
 
170
  # Downloadable audio file
171
+ st.download_button(
172
+ label="Download Audio",
173
+ data=st.session_state.wav_audio_file_audio,
174
+ file_name="converted_audio_audio.wav",
175
+ mime="audio/wav"
176
+ )