Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created November 28, 2023 12:30
Show Gist options
  • Save KaushikShresth07/ba9589c3585deeab4d004dd908811189 to your computer and use it in GitHub Desktop.
Save KaushikShresth07/ba9589c3585deeab4d004dd908811189 to your computer and use it in GitHub Desktop.
import sounddevice as sd
import numpy as np
threshold = 90
Clap = False
def detect_clap(indata,frames,time,status):
global Clap
volume_norm = np.linalg.norm(indata) * 10
if volume_norm>threshold:
print("Clapped!")
Clap = True
def Listen_for_claps():
with sd.InputStream(callback=detect_clap):
return sd.sleep(1000)
def MainClapExe():
while True:
Listen_for_claps()
if Clap==True:
break
else:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment