Notes
Notes - notes.io |
from tkinter import messagebox
import tkinter.ttk as ttk
import numpy as np
import librosa
from pydub import AudioSegment
import os
import tempfile
import pickle
class EmotionClassifierApp:
def __init__(self, root):
self.root = root
self.root.title("Emotion Classifier App")
self.root.geometry("400x200")
self.load_model()
self.create_widgets()
def create_widgets(self):
self.btn_record = ttk.Button(self.root, text="Record Voice", command=self.record_voice)
self.btn_record.pack(pady=10)
self.lbl_result = ttk.Label(self.root, text="")
self.lbl_result.pack(pady=10)
self.btn_quit = ttk.Button(self.root, text="Quit", command=self.root.quit)
self.btn_quit.pack(pady=10)
def load_model(self):
model_path = "your_model.pkl" # Provide the path to your pickled model
with open(model_path, 'rb') as f:
self.model = pickle.load(f)
def record_voice(self):
temp_audio_file = os.path.join(tempfile.gettempdir(), "temp_audio.wav")
# Record audio
os.system("rec -r 44100 -c 2 -b 16 " + temp_audio_file + " silence 1 0.1 1% 1 3.0 1%")
# Load recorded audio
data, sample_rate = librosa.load(temp_audio_file)
# Delete temporary audio file
os.remove(temp_audio_file)
try:
features = self.extract_features(data, sample_rate)
features = np.expand_dims(features, axis=0)
features = np.expand_dims(features, axis=2)
prediction = self.model.predict(features)
predicted_emotion = self.encoder.inverse_transform(prediction)[0]
self.lbl_result.config(text=f"Predicted Emotion: {predicted_emotion}")
except Exception as e:
messagebox.showerror("Error", str(e))
def extract_features(self, data, sample_rate):
result = np.array([])
zcr = np.mean(librosa.feature.zero_crossing_rate(y=data).T, axis=0)
result = np.hstack((result, zcr))
stft = np.abs(librosa.stft(data))
chroma_stft = np.mean(librosa.feature.chroma_stft(S=stft, sr=sample_rate).T, axis=0)
result = np.hstack((result, chroma_stft))
mfcc = np.mean(librosa.feature.mfcc(y=data, sr=sample_rate).T, axis=0)
result = np.hstack((result, mfcc))
rms = np.mean(librosa.feature.rms(y=data).T, axis=0)
result = np.hstack((result, rms))
mel = np.mean(librosa.feature.melspectrogram(y=data, sr=sample_rate).T, axis=0)
result = np.hstack((result, mel))
return result
if __name__ == "__main__":
root = tk.Tk()
app = EmotionClassifierApp(root)
root.mainloop()
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team