Spaces:
Running
Running
Gregory2041
commited on
Commit
•
7b8298a
1
Parent(s):
d4c90c2
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,14 @@
|
|
1 |
# Importing the required libraries
|
2 |
-
import os
|
3 |
-
os.system('apt-get update && apt-get install -y portaudio19-dev')
|
4 |
-
|
5 |
import streamlit as st
|
6 |
-
import sounddevice as sd
|
7 |
import numpy as np
|
8 |
-
from scipy.io.wavfile import write
|
9 |
import librosa
|
10 |
import matplotlib.pyplot as plt
|
11 |
from tensorflow.keras.models import Sequential, load_model
|
12 |
from tensorflow.keras.layers import Dense, Dropout
|
13 |
-
import io
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Set the device ID (replace 'device_id' with the actual ID)
|
18 |
-
device_id = 1 # Example: choose the correct device ID from the list
|
19 |
-
sd.default.device = device_id
|
20 |
|
21 |
# Define the target speakers in a list.
|
22 |
# ALSO THESE ARE FILES THAT WERE NOT USED TO TEST NOR TRAIN THE MODEL
|
@@ -150,49 +142,45 @@ if uploaded_file is not None:
|
|
150 |
speaker, probability, _ = classify_speaker("uploaded_audio.wav")
|
151 |
gender, gen_probability = classify_gender("uploaded_audio.wav")
|
152 |
|
153 |
-
#
|
154 |
st.write(f"Predicted Gender: {gender}")
|
155 |
|
156 |
-
#
|
157 |
st.write(f"Gender Probability: {gen_probability}")
|
158 |
|
159 |
# Which speaker is it?
|
160 |
st.write(f"Predicted Speaker: {speaker}")
|
161 |
|
162 |
-
#
|
163 |
st.write(f"Speaker Probability: {probability}")
|
164 |
|
165 |
except Exception as e:
|
166 |
st.error(f"Error occurred: {e}")
|
167 |
|
168 |
-
# Record audio with
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
audio_to_spectrogram(
|
181 |
st.image("spectrogram.png", caption="Mel Spectrogram of the recorded audio file", use_column_width="auto", width=200)
|
182 |
-
|
183 |
-
|
|
|
|
|
184 |
|
185 |
-
#
|
186 |
st.write(f"Predicted Gender: {gender}")
|
187 |
-
|
188 |
-
# how much do u sound like this speaker?
|
189 |
st.write(f"Gender Probability: {gen_probability}")
|
190 |
-
|
191 |
-
# who do u sound like the most?
|
192 |
st.write(f"Predicted Speaker: {speaker}")
|
193 |
-
|
194 |
-
# how much do u sound like this speaker?
|
195 |
st.write(f"Speaker Probability: {probability}")
|
196 |
|
197 |
-
# speaker
|
198 |
st.audio(wav_file)
|
|
|
1 |
# Importing the required libraries
|
|
|
|
|
|
|
2 |
import streamlit as st
|
|
|
3 |
import numpy as np
|
|
|
4 |
import librosa
|
5 |
import matplotlib.pyplot as plt
|
6 |
from tensorflow.keras.models import Sequential, load_model
|
7 |
from tensorflow.keras.layers import Dense, Dropout
|
8 |
+
import io
|
9 |
+
import soundfile as sf
|
10 |
+
from streamlit_audio_recorder import st_audiorec
|
11 |
+
from scipy.io.wavfile import write, read as wav_read
|
|
|
|
|
|
|
12 |
|
13 |
# Define the target speakers in a list.
|
14 |
# ALSO THESE ARE FILES THAT WERE NOT USED TO TEST NOR TRAIN THE MODEL
|
|
|
142 |
speaker, probability, _ = classify_speaker("uploaded_audio.wav")
|
143 |
gender, gen_probability = classify_gender("uploaded_audio.wav")
|
144 |
|
145 |
+
# What's the gender of speaker?
|
146 |
st.write(f"Predicted Gender: {gender}")
|
147 |
|
148 |
+
# What's the shot of speaker being a male or female
|
149 |
st.write(f"Gender Probability: {gen_probability}")
|
150 |
|
151 |
# Which speaker is it?
|
152 |
st.write(f"Predicted Speaker: {speaker}")
|
153 |
|
154 |
+
# What's the chances of being the speaker?
|
155 |
st.write(f"Speaker Probability: {probability}")
|
156 |
|
157 |
except Exception as e:
|
158 |
st.error(f"Error occurred: {e}")
|
159 |
|
160 |
+
# Record audio with streamlit_audio_recorder
|
161 |
+
recorded_audio = st_audiorec()
|
162 |
+
|
163 |
+
if recorded_audio:
|
164 |
+
# Save the audio as a .wav file
|
165 |
+
with open("recorded_audio.wav", "wb") as f:
|
166 |
+
f.write(recorded_audio)
|
167 |
+
|
168 |
+
st.write(f"Audio recorded and saved to recorded_audio.wav") # Show message
|
169 |
+
st.audio("recorded_audio.wav") # Show the audio file
|
170 |
+
|
171 |
+
# Process the recorded audio
|
172 |
+
audio_to_spectrogram("recorded_audio.wav")
|
173 |
st.image("spectrogram.png", caption="Mel Spectrogram of the recorded audio file", use_column_width="auto", width=200)
|
174 |
+
|
175 |
+
# Classify the speaker and gender
|
176 |
+
speaker, probability, wav_file = classify_speaker("recorded_audio.wav")
|
177 |
+
gender, gen_probability = classify_gender("recorded_audio.wav")
|
178 |
|
179 |
+
# Display results
|
180 |
st.write(f"Predicted Gender: {gender}")
|
|
|
|
|
181 |
st.write(f"Gender Probability: {gen_probability}")
|
|
|
|
|
182 |
st.write(f"Predicted Speaker: {speaker}")
|
|
|
|
|
183 |
st.write(f"Speaker Probability: {probability}")
|
184 |
|
185 |
+
# Display the wav file of the predicted speaker
|
186 |
st.audio(wav_file)
|