supression canvas, ajout label, lancement de microphone au lieu de affichage, micro op, affichage op

This commit is contained in:
Mylloon 2020-11-30 22:22:43 +01:00
parent d1da2216a7
commit bc1f6efe5f

29
soui.py
View file

@ -6,27 +6,21 @@ from tkinter import Tk, Canvas, Label, PhotoImage
class Microphone:
def __init__(self):
self.buffer = 0.1 # seconds
self.speaking = False
def audio_callback(self, indata, frames, time, status):
volume_norm = np.linalg.norm(indata) * 10
if int(volume_norm) > 2 and not self.speaking:
if int(volume_norm) > 2:
self.speaking = True
elif int(volume_norm) < 2 and self.speaking:
elif int(volume_norm) < 2:
self.speaking = False
def get_status_speaking(self):
return self.speaking
def repeat(self):
print(self.speaking)
sleep(self.buffer)
return self.repeat()
def start(self):
with sd.InputStream(callback = self.audio_callback):
self.repeat()
Affichage().start()
class Affichage:
@ -36,28 +30,29 @@ class Affichage:
self.notspeaking = "not_speaking.png"
def refresh(self):
self.canvas.itemconfig(self.canvas_image, image = PhotoImage(master = self.fenetre, file = self.get_image()))
self.get_image()
self.label.config(image = self.img)
self.fenetre.update_idletasks()
self.fenetre.after(self.buffer, self.refresh)
def get_image(self):
if Microphone().get_status_speaking():
print("parle")
return self.speaking
self.img = PhotoImage(file = self.speaking)
else:
print("parle pas")
return self.notspeaking
self.img = PhotoImage(file = self.notspeaking)
def start(self):
self.fenetre = Tk()
self.fenetre.title('Microphone')
self.canvas = Canvas(self.fenetre)
self.canvas.configure(width = 1080, height = 2140)
self.canvas_image = self.canvas.create_image(540, 1070, image = PhotoImage(master = self.fenetre, file = self.get_image()))
self.fenetre.geometry("357x697")
self.get_image()
self.label = Label(self.fenetre, image = self.img)
self.label.pack(fill = "both", expand = "yes")
self.refresh()
self.fenetre.mainloop()
if __name__ == '__main__':
Affichage().start()
Microphone().start()