pipenv: add sound-run; sound.py: --input-device flag
This commit is contained in:
1
Pipfile
1
Pipfile
@@ -34,3 +34,4 @@ flash-esp32 = "bash -c 'source $HOME/esp/esp-idf/export.sh && cd esp32 && idf.py
|
|||||||
watch-esp32 = "watchfiles 'bash -c \"source $HOME/esp/esp-idf/export.sh && cd esp32 && idf.py -p ${ESPPORT:-/dev/ttyACM0} -b ${ESPSPEED:-460800} flash monitor\"' esp32/main"
|
watch-esp32 = "watchfiles 'bash -c \"source $HOME/esp/esp-idf/export.sh && cd esp32 && idf.py -p ${ESPPORT:-/dev/ttyACM0} -b ${ESPSPEED:-460800} flash monitor\"' esp32/main"
|
||||||
send-json = "python test/send_json.py"
|
send-json = "python test/send_json.py"
|
||||||
send-net = "python test/test_networking.py"
|
send-net = "python test/test_networking.py"
|
||||||
|
sound-run = "python src/sound.py"
|
||||||
|
|||||||
11
src/sound.py
11
src/sound.py
@@ -5,6 +5,7 @@ import aubio
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import json
|
import json
|
||||||
|
import argparse
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import logging # Added logging import
|
import logging # Added logging import
|
||||||
@@ -24,7 +25,7 @@ SOUND_CONTROL_HOST = "127.0.0.1"
|
|||||||
SOUND_CONTROL_PORT = 65433
|
SOUND_CONTROL_PORT = 65433
|
||||||
|
|
||||||
class SoundBeatDetector:
|
class SoundBeatDetector:
|
||||||
def __init__(self, tcp_host: str, tcp_port: int):
|
def __init__(self, tcp_host: str, tcp_port: int, *, input_device: int | None = None):
|
||||||
self.tcp_host = tcp_host
|
self.tcp_host = tcp_host
|
||||||
self.tcp_port = tcp_port
|
self.tcp_port = tcp_port
|
||||||
self.tcp_socket = None
|
self.tcp_socket = None
|
||||||
@@ -34,7 +35,7 @@ class SoundBeatDetector:
|
|||||||
|
|
||||||
self.bufferSize = 512
|
self.bufferSize = 512
|
||||||
self.windowSizeMultiple = 2
|
self.windowSizeMultiple = 2
|
||||||
self.audioInputDeviceIndex = 7
|
self.audioInputDeviceIndex = 7 if input_device is None else int(input_device)
|
||||||
self.audioInputChannels = 1
|
self.audioInputChannels = 1
|
||||||
|
|
||||||
self.pa = pyaudio.PyAudio()
|
self.pa = pyaudio.PyAudio()
|
||||||
@@ -196,11 +197,15 @@ class SoundBeatDetector:
|
|||||||
# Removed async def run(self)
|
# Removed async def run(self)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(description="Sound beat detector")
|
||||||
|
parser.add_argument("--input-device", type=int, help="Audio input device index to use")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
# TCP Server Configuration (should match midi.py)
|
# TCP Server Configuration (should match midi.py)
|
||||||
MIDI_TCP_HOST = "127.0.0.1"
|
MIDI_TCP_HOST = "127.0.0.1"
|
||||||
MIDI_TCP_PORT = 65432
|
MIDI_TCP_PORT = 65432
|
||||||
|
|
||||||
sound_detector = SoundBeatDetector(MIDI_TCP_HOST, MIDI_TCP_PORT)
|
sound_detector = SoundBeatDetector(MIDI_TCP_HOST, MIDI_TCP_PORT, input_device=args.input_device)
|
||||||
logging.info("Starting SoundBeatDetector...")
|
logging.info("Starting SoundBeatDetector...")
|
||||||
try:
|
try:
|
||||||
sound_detector.start_stream()
|
sound_detector.start_stream()
|
||||||
|
|||||||
Reference in New Issue
Block a user