Last active
May 11, 2021 12:19
-
-
Save gose/43e45cc6c8e56903cd0f3821298f0a06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
import pyaudio | |
import numpy | |
import wave | |
CHUNK = 4000 | |
FORMAT = pyaudio.paInt16 | |
CHANNELS = 1 | |
RATE = 8000 | |
audio = pyaudio.PyAudio() | |
stream = audio.open(format=FORMAT, | |
channels=CHANNELS, | |
rate=RATE, | |
input=True, | |
frames_per_buffer=CHUNK) | |
log = open("/var/log/sounds.log", "a") | |
# Use a Blackman window | |
window = numpy.blackman(CHUNK) | |
while True: | |
data = stream.read(CHUNK, exception_on_overflow=False) | |
waveData = wave.struct.unpack("%dh"%(CHUNK), data) | |
npArrayData = numpy.array(waveData) | |
indata = npArrayData * window | |
for i in indata: | |
log.write(datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f000Z') + ";" + str(i) + "\n") | |
log.close() | |
stream.stop_stream() | |
stream.close() | |
audio.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment