release
This commit is contained in:
parent
bc1f6efe5f
commit
84f4a796e1
1 changed files with 9 additions and 10 deletions
19
soui.py
19
soui.py
|
@ -3,20 +3,20 @@ import sounddevice as sd
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from tkinter import Tk, Canvas, Label, PhotoImage
|
from tkinter import Tk, Canvas, Label, PhotoImage
|
||||||
|
|
||||||
|
speaking = False
|
||||||
|
|
||||||
class Microphone:
|
class Microphone:
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.speaking = False
|
|
||||||
|
|
||||||
def audio_callback(self, indata, frames, time, status):
|
def audio_callback(self, indata, frames, time, status):
|
||||||
|
global speaking
|
||||||
volume_norm = np.linalg.norm(indata) * 10
|
volume_norm = np.linalg.norm(indata) * 10
|
||||||
if int(volume_norm) > 2:
|
if int(volume_norm) > 2 and speaking == False:
|
||||||
self.speaking = True
|
speaking = True
|
||||||
elif int(volume_norm) < 2:
|
elif int(volume_norm) < 2 and speaking == True:
|
||||||
self.speaking = False
|
speaking = False
|
||||||
|
|
||||||
def get_status_speaking(self):
|
def get_status_speaking(self):
|
||||||
return self.speaking
|
return speaking
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
with sd.InputStream(callback = self.audio_callback):
|
with sd.InputStream(callback = self.audio_callback):
|
||||||
|
@ -25,7 +25,7 @@ class Microphone:
|
||||||
class Affichage:
|
class Affichage:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.buffer = 500 # milliseconds
|
self.buffer = 100 # milliseconds
|
||||||
self.speaking = "speaking.png"
|
self.speaking = "speaking.png"
|
||||||
self.notspeaking = "not_speaking.png"
|
self.notspeaking = "not_speaking.png"
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ class Affichage:
|
||||||
|
|
||||||
def get_image(self):
|
def get_image(self):
|
||||||
if Microphone().get_status_speaking():
|
if Microphone().get_status_speaking():
|
||||||
print("parle")
|
|
||||||
self.img = PhotoImage(file = self.speaking)
|
self.img = PhotoImage(file = self.speaking)
|
||||||
else:
|
else:
|
||||||
self.img = PhotoImage(file = self.notspeaking)
|
self.img = PhotoImage(file = self.notspeaking)
|
||||||
|
|
Reference in a new issue