Update app.py
Browse files
app.py
CHANGED
@@ -62,4 +62,49 @@ if "recorded_file" not in st.session_state:
|
|
62 |
st.session_state["recorded_file"] = None
|
63 |
|
64 |
if st.button("Grabando..."):
|
65 |
-
print("Subir Audio de prueba")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
st.session_state["recorded_file"] = None
|
63 |
|
64 |
if st.button("Grabando..."):
|
65 |
+
print("Subir Audio de prueba")
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
import streamlit as st
|
74 |
+
import librosa
|
75 |
+
import librosa.display
|
76 |
+
import matplotlib.pyplot as plt
|
77 |
+
import numpy as np
|
78 |
+
import soundfile as sf
|
79 |
+
import io
|
80 |
+
|
81 |
+
|
82 |
+
if audio_file is not None:
|
83 |
+
# Cargar audio con librosa
|
84 |
+
audio_bytes = audio_file.read()
|
85 |
+
y, sr = librosa.load(io.BytesIO(audio_bytes), sr=None)
|
86 |
+
|
87 |
+
st.audio(audio_bytes, format='audio/mp3')
|
88 |
+
|
89 |
+
# Mostrar informaci贸n del audio
|
90 |
+
duration = librosa.get_duration(y=y, sr=sr)
|
91 |
+
st.markdown(f"**Duraci贸n:** {duration:.2f} segundos")
|
92 |
+
st.markdown(f"**Tasa de muestreo:** {sr} Hz")
|
93 |
+
|
94 |
+
# Forma de onda
|
95 |
+
st.subheader("Forma de Onda")
|
96 |
+
fig_wave, ax_wave = plt.subplots(figsize=(10, 3))
|
97 |
+
librosa.display.waveshow(y, sr=sr, ax=ax_wave)
|
98 |
+
ax_wave.set_title("Forma de Onda")
|
99 |
+
ax_wave.set_xlabel("Tiempo (s)")
|
100 |
+
ax_wave.set_ylabel("Amplitud")
|
101 |
+
st.pyplot(fig_wave)
|
102 |
+
|
103 |
+
# Espectrograma
|
104 |
+
st.subheader("Espectrograma")
|
105 |
+
fig_spec, ax_spec = plt.subplots(figsize=(10, 4))
|
106 |
+
D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max)
|
107 |
+
img = librosa.display.specshow(D, sr=sr, x_axis='time', y_axis='log', ax=ax_spec)
|
108 |
+
ax_spec.set_title("Espectrograma Logar铆tmico")
|
109 |
+
fig_spec.colorbar(img, ax=ax_spec, format="%+2.f dB")
|
110 |
+
st.pyplot(fig_spec)
|