Spaces:
Running
Running
audi file format
Browse files
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
|
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 |
-
|
|
|
123 |
|
124 |
-
#
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
#
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
#
|
135 |
-
st.
|
|
|
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 |
|