python/clap.py: fix
This commit is contained in:
parent
4bdddd6451
commit
9c2b2312f1
@ -1,10 +1,11 @@
|
|||||||
#!/usr/bin/env nix-script
|
#!/usr/bin/env nix-script
|
||||||
#!>python
|
#!>python
|
||||||
#! python | pyaudio
|
#! python3 | pyaudio
|
||||||
|
|
||||||
## Listen to claps from the microphone.
|
## Listen to claps from the microphone.
|
||||||
|
|
||||||
import pyaudio, audioop
|
import pyaudio
|
||||||
|
import audioop
|
||||||
|
|
||||||
settings = {
|
settings = {
|
||||||
"format": pyaudio.paInt16,
|
"format": pyaudio.paInt16,
|
||||||
@ -14,15 +15,14 @@ settings = {
|
|||||||
"frames_per_buffer": 1024
|
"frames_per_buffer": 1024
|
||||||
}
|
}
|
||||||
audio = pyaudio.PyAudio()
|
audio = pyaudio.PyAudio()
|
||||||
stream = audio.open(**impostazioni)
|
stream = audio.open(**settings)
|
||||||
chunk = int(impostazioni["rate"] * 0.025)
|
chunk = int(settings["rate"] * 0.025)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
noisy = 0
|
noisy = 0
|
||||||
for i in range(10):
|
for i in range(5):
|
||||||
block = stream.read(chunk)
|
block = stream.read(chunk, exception_on_overflow=False)
|
||||||
if audioop.rms(block, 2) > 100:
|
if audioop.rms(block, 2) > 100:
|
||||||
noisy += 1
|
noisy += 1
|
||||||
if 3 <= noisy < 8:
|
if 3 <= noisy < 8:
|
||||||
print("clap")
|
print("clap")
|
||||||
|
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# Packages required
|
|
||||||
# dosfstools parted
|
|
||||||
# Can be run on any Linux system
|
|
||||||
# loop.max_part=15 must be in kernel cmdline (cmdline.txt for rpi)
|
|
||||||
# then reboot
|
|
||||||
|
|
||||||
echo "creating image to fit on 2Gb card"
|
|
||||||
dd if=/dev/zero of=arch-rpi.img bs=1M count=1850
|
|
||||||
|
|
||||||
echo "Partitioning"
|
|
||||||
fdisk arch-rpi.img <<EOF
|
|
||||||
o
|
|
||||||
n
|
|
||||||
p
|
|
||||||
1
|
|
||||||
|
|
||||||
+100M
|
|
||||||
|
|
||||||
t
|
|
||||||
c
|
|
||||||
n
|
|
||||||
p
|
|
||||||
2
|
|
||||||
|
|
||||||
|
|
||||||
w
|
|
||||||
EOF
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
losetup -f arch-rpi.img
|
|
||||||
sleep 5
|
|
||||||
kpartx -a /dev/loop0
|
|
||||||
|
|
||||||
echo "Formatting vfat"
|
|
||||||
mkfs.vfat /dev/loop0p1
|
|
||||||
sleep 5
|
|
||||||
mkdir boot
|
|
||||||
echo "Mounting boot"
|
|
||||||
mount /dev/loop0p1 boot
|
|
||||||
echo "Installing"
|
|
||||||
|
|
||||||
echo "Formatting ext4"
|
|
||||||
mkfs.ext4 /dev/loop0p2
|
|
||||||
sleep 5
|
|
||||||
mkdir root
|
|
||||||
echo "Mounting root"
|
|
||||||
mount /dev/loop0p2 root
|
|
||||||
|
|
||||||
wget http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz
|
|
||||||
echo "Installing"
|
|
||||||
bsdtar -xpf ArchLinuxARM-rpi-latest.tar.gz -C root
|
|
||||||
sync
|
|
||||||
mv root/boot/* boot
|
|
||||||
sync
|
|
||||||
umount boot root
|
|
||||||
losetup -d /dev/loop0p1
|
|
||||||
losetup -d /dev/loop0p1
|
|
||||||
losetup -d /dev/loop0
|
|
||||||
echo "All complete, image arch-rpi.img created, compressing...."
|
|
||||||
zip -9 arch-rpi.img.zip arch-rpi.img
|
|
Loading…
Reference in New Issue
Block a user