summaryrefslogtreecommitdiff
path: root/assets/realtime-beat-detector.py
diff options
context:
space:
mode:
authorsaberr26 <salahhachmi06@gmail.com>2025-06-11 09:57:29 +0100
committerGitHub <noreply@github.com>2025-06-11 09:57:29 +0100
commit14198f54591c635c348f944fa26e93c32f09dea8 (patch)
tree798d7e37df746d4e44d96147a176bd4cb250d6e2 /assets/realtime-beat-detector.py
parentMerge pull request #43 from Amstel-DEV/main (diff)
downloadcaelestia-shell-14198f54591c635c348f944fa26e93c32f09dea8.tar.gz
caelestia-shell-14198f54591c635c348f944fa26e93c32f09dea8.tar.bz2
caelestia-shell-14198f54591c635c348f944fa26e93c32f09dea8.zip
removed realtime-beat-detector.py and Add C++ real-time audio analyzer
Diffstat (limited to 'assets/realtime-beat-detector.py')
-rwxr-xr-xassets/realtime-beat-detector.py73
1 files changed, 0 insertions, 73 deletions
diff --git a/assets/realtime-beat-detector.py b/assets/realtime-beat-detector.py
deleted file mode 100755
index 0f4f54a..0000000
--- a/assets/realtime-beat-detector.py
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/usr/bin/env python
-
-import pyaudio
-import numpy as np
-import aubio
-import signal
-import sys
-
-from typing import List, Tuple
-
-
-class BeatDetector:
- def __init__(self, buf_size: int):
- self.buf_size: int = buf_size
-
- # Set up pyaudio and aubio beat detector
- self.audio: pyaudio.PyAudio = pyaudio.PyAudio()
- samplerate: int = 44100
-
- self.stream: pyaudio.Stream = self.audio.open(
- format=pyaudio.paFloat32,
- channels=1,
- rate=samplerate,
- input=True,
- frames_per_buffer=self.buf_size,
- stream_callback=self._pyaudio_callback
- )
-
- fft_size: int = self.buf_size * 2
-
- # tempo detection
- self.tempo: aubio.tempo = aubio.tempo("default", fft_size, self.buf_size, samplerate)
-
- # this one is called every time enough audio data (buf_size) has been read by the stream
- def _pyaudio_callback(self, in_data, frame_count, time_info, status):
- # Interpret a buffer as a 1-dimensional array (aubio do not work with raw data)
- audio_data = np.frombuffer(in_data, dtype=np.float32)
- # true if beat present
- beat = self.tempo(audio_data)
-
- # if beat detected, calculate BPM and send to OSC
- if beat[0]:
- print(self.tempo.get_bpm(), flush=True)
-
- return None, pyaudio.paContinue # Tell pyAudio to continue
-
- def __del__(self):
- self.stream.close()
- self.audio.terminate()
- print('--- Stopped ---')
-
-
-# main
-def main():
- bd = BeatDetector(512)
-
- # capture ctrl+c to stop gracefully process
- def signal_handler(none, frame):
- bd.stream.stop_stream()
- bd.stream.close()
- bd.audio.terminate()
- print(' ===> Ctrl + C')
- sys.exit(0)
-
- signal.signal(signal.SIGINT, signal_handler)
-
- # Audio processing happens in separate thread, so put this thread to sleep
- signal.pause()
-
-
-# main run
-if __name__ == "__main__":
- main()