Process audio from JACK. Draft, not working

main
Jeff Moe 2023-09-24 14:08:44 -06:00
parent c518ebd655
commit c81ef26d3a
1 changed files with 81 additions and 0 deletions

81
sndid-jack.py 100755
View File

@ -0,0 +1,81 @@
#!/usr/bin/env python3
"""
sndid-jack
Copyright 2023, Jeff Moe <moe@spacecruft.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from datetime import datetime
import socketserver
import argparse
from contextlib import redirect_stdout, redirect_stderr
import io
import numpy as np
import time
import threading
import jack
from birdnetlib import RecordingBuffer
from birdnetlib.analyzer import Analyzer
clientname = "Deepcrayon"
client = jack.Client(clientname)
event = threading.Event()
f = io.StringIO()
client.inports.register("input_1")
client.inports.register("input_2")
@client.set_process_callback
def process(frames):
assert len(client.inports)
assert frames == client.blocksize
for port in client.inports:
data = port.get_array()
print(data)
with redirect_stdout(f), redirect_stderr(f):
analyzer = Analyzer()
with redirect_stdout(f), redirect_stderr(f):
recording = RecordingBuffer(
analyzer,
data,
48000,
lat=40,
lon=-105,
date=datetime(year=2023, month=9, day=24),
min_conf=0.25,
)
@client.set_shutdown_callback
def shutdown(status, reason):
print("JACK shutdown!")
print("status:", status)
print("reason:", reason)
event.set()
with client:
client.connect("ardour:Master/audio_out 1", "Deepcrayon:input_1")
client.connect("ardour:Master/audio_out 2", "Deepcrayon:input_2")
print("Press Ctrl+C to stop")
try:
event.wait()
except KeyboardInterrupt:
print("\nInterrupted by user")