pipenv: add sound-run; sound.py: --input-device flag
This commit is contained in:
11
src/sound.py
11
src/sound.py
@@ -5,6 +5,7 @@ import aubio
|
||||
import numpy as np
|
||||
from time import sleep
|
||||
import json
|
||||
import argparse
|
||||
import socket
|
||||
import time
|
||||
import logging # Added logging import
|
||||
@@ -24,7 +25,7 @@ SOUND_CONTROL_HOST = "127.0.0.1"
|
||||
SOUND_CONTROL_PORT = 65433
|
||||
|
||||
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_port = tcp_port
|
||||
self.tcp_socket = None
|
||||
@@ -34,7 +35,7 @@ class SoundBeatDetector:
|
||||
|
||||
self.bufferSize = 512
|
||||
self.windowSizeMultiple = 2
|
||||
self.audioInputDeviceIndex = 7
|
||||
self.audioInputDeviceIndex = 7 if input_device is None else int(input_device)
|
||||
self.audioInputChannels = 1
|
||||
|
||||
self.pa = pyaudio.PyAudio()
|
||||
@@ -196,11 +197,15 @@ class SoundBeatDetector:
|
||||
# Removed async def run(self)
|
||||
|
||||
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)
|
||||
MIDI_TCP_HOST = "127.0.0.1"
|
||||
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...")
|
||||
try:
|
||||
sound_detector.start_stream()
|
||||
|
Reference in New Issue
Block a user