multiprocess analysis, no jack xruns
parent
681a1dec62
commit
3801e8b7a5
|
@ -30,6 +30,7 @@ import threading
|
|||
import jack
|
||||
from birdnetlib import RecordingBuffer
|
||||
from birdnetlib.analyzer import Analyzer
|
||||
from multiprocessing import Process
|
||||
|
||||
clientname = "Deepcrayon"
|
||||
client = jack.Client(clientname)
|
||||
|
@ -40,17 +41,50 @@ f = io.StringIO()
|
|||
client.inports.register("input_1")
|
||||
client.inports.register("input_2")
|
||||
|
||||
segment = np.ndarray([1024,])
|
||||
segment = np.ndarray(
|
||||
[
|
||||
1024,
|
||||
]
|
||||
)
|
||||
segment_analyze = np.ndarray(
|
||||
[
|
||||
1024,
|
||||
]
|
||||
)
|
||||
n = 0
|
||||
|
||||
# Do one analysis in advance on nothing, just to get everything loaded.
|
||||
with redirect_stdout(f), redirect_stderr(f):
|
||||
analyzer = Analyzer()
|
||||
with redirect_stdout(f), redirect_stderr(f):
|
||||
recording = RecordingBuffer(
|
||||
analyzer,
|
||||
segment_analyze,
|
||||
48000,
|
||||
lat=40,
|
||||
lon=-105,
|
||||
date=datetime(year=2023, month=9, day=24),
|
||||
min_conf=0.25,
|
||||
)
|
||||
with redirect_stdout(f), redirect_stderr(f):
|
||||
detection = recording.analyze()
|
||||
print(recording.detections)
|
||||
|
||||
|
||||
@client.set_process_callback
|
||||
def process(frames):
|
||||
global data
|
||||
global segment
|
||||
global n
|
||||
assert len(client.inports)
|
||||
assert frames == client.blocksize
|
||||
for port in client.inports:
|
||||
data = port.get_array()
|
||||
segment_data()
|
||||
segment = np.append(segment, data, axis=0)
|
||||
n = n + 1
|
||||
if n > 255:
|
||||
segment_data()
|
||||
n = 0
|
||||
|
||||
|
||||
@client.set_shutdown_callback
|
||||
|
@ -63,34 +97,37 @@ def shutdown(status, reason):
|
|||
|
||||
def segment_data():
|
||||
global segment
|
||||
global data
|
||||
global n
|
||||
segment = np.append(segment, data, axis=0)
|
||||
n = n + 1
|
||||
if n > 1024:
|
||||
analyze()
|
||||
n = 0
|
||||
global p
|
||||
segment_analyze = segment
|
||||
segment = np.ndarray(
|
||||
[
|
||||
1024,
|
||||
]
|
||||
)
|
||||
p = Process(target=analyze())
|
||||
p.start()
|
||||
|
||||
|
||||
def analyze():
|
||||
global segment
|
||||
global n
|
||||
with redirect_stdout(f), redirect_stderr(f):
|
||||
analyzer = Analyzer()
|
||||
global segment_analyze
|
||||
with redirect_stdout(f), redirect_stderr(f):
|
||||
recording = RecordingBuffer(
|
||||
analyzer,
|
||||
segment,
|
||||
segment_analyze,
|
||||
48000,
|
||||
lat=40,
|
||||
lon=-105,
|
||||
date=datetime(year=2023, month=9, day=24),
|
||||
min_conf=0.25,
|
||||
)
|
||||
segment_analyze = np.ndarray(
|
||||
[
|
||||
1024,
|
||||
]
|
||||
)
|
||||
with redirect_stdout(f), redirect_stderr(f):
|
||||
detection = recording.analyze()
|
||||
print(recording.detections)
|
||||
segment = np.ndarray([1024,])
|
||||
|
||||
|
||||
with client:
|
||||
|
|
Loading…
Reference in New Issue