AAhad commited on
Commit
8742ee2
·
1 Parent(s): 11c3ed2

audi file format

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -110,29 +110,28 @@ if audio_option == 'Record Audio':
110
 
111
  # Option 2: Upload audio
112
  elif audio_option == 'Upload Audio':
113
- audio_file = st.file_uploader("Upload audio file (WAV format)", type=['wav'])
114
-
 
 
115
  if audio_file:
116
-
117
- # When writing the audio data, specify the format explicitly
118
- with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
119
- sf.write(tmp_file.name, audio_data, sr, format='WAV')
120
- tmp_file_path = tmp_file.name
121
 
122
- audio_data, sr = librosa.load(tmp_file_path, sr=None)
 
123
 
124
- # Compute audio properties
125
- audio_size = len(audio_data) * 2 # in bytes (16-bit PCM)
126
- frame_rate = sr
127
- duration = librosa.get_duration(y=audio_data, sr=sr)
128
-
129
- # Display audio properties
130
- st.write(f"Audio Size: {audio_size} bytes")
131
- st.write(f"Frame Rate: {frame_rate} Hz")
132
- st.write(f"Duration: {duration:.2f} seconds")
133
-
134
- # Perform conversion using the selected model
135
- st.subheader("Converting audio to text...")
 
136
 
137
  start_time = time.time()
138
 
 
110
 
111
  # Option 2: Upload audio
112
  elif audio_option == 'Upload Audio':
113
+ audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
114
+ # Assuming you're working with an uploaded file
115
+ # uploaded_file = st.file_uploader("Upload an audio file", type=["wav", "mp3", "ogg"])
116
+
117
  if audio_file:
 
 
 
 
 
118
 
119
+ # Read the uploaded audio file
120
+ audio_data, sr = librosa.load(audio_file, sr=None) # sr=None preserves original sample rate
121
 
122
+ # Display information about the audio file
123
+ st.write(f"Audio file size: {audio_file.size} bytes")
124
+ st.write(f"Sample rate: {sr}")
125
+ st.write(f"Duration: {len(audio_data) / sr:.2f} seconds")
126
+
127
+ # Convert the audio to WAV format and save as temporary file
128
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_file:
129
+ sf.write(tmp_file.name, audio_data, sr, format='WAV')
130
+ tmp_file_path = tmp_file.name
131
+
132
+ # Now you can proceed with the ASR model for conversion
133
+ st.write("Converting audio to text...")
134
+ # (Your ASR model conversion code goes here)
135
 
136
  start_time = time.time()
137