mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
removed the selected audio device logic
This commit is contained in:
parent
f17464fc5a
commit
9415bf04eb
1 changed files with 30 additions and 21 deletions
|
|
@ -4,25 +4,34 @@ import curses
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
|
import tempfile
|
||||||
AUDIO_DEVICE = "hw:1" # Change this if needed
|
import os
|
||||||
|
|
||||||
def read_ltc():
|
def read_ltc():
|
||||||
ffmpeg = subprocess.Popen(
|
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
||||||
["ffmpeg", "-f", "alsa", "-i", AUDIO_DEVICE, "-t", "1", "-f", "s16le", "-ac", "1", "-ar", "48000", "-"],
|
wav_path = tmp.name
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
stderr=subprocess.DEVNULL
|
try:
|
||||||
)
|
# Record 1 second of audio from default device
|
||||||
ltcdump = subprocess.Popen(
|
subprocess.run([
|
||||||
["ltcdump", "-f", "-"],
|
"ffmpeg", "-f", "alsa", "-i", "default",
|
||||||
stdin=ffmpeg.stdout,
|
"-t", "1", "-ac", "1", "-ar", "48000", "-y", wav_path
|
||||||
stdout=subprocess.PIPE,
|
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
stderr=subprocess.DEVNULL
|
|
||||||
)
|
# Decode LTC from the recorded file
|
||||||
ffmpeg.stdout.close()
|
result = subprocess.run(
|
||||||
output, _ = ltcdump.communicate()
|
["ltcdump", wav_path],
|
||||||
lines = output.decode().splitlines()
|
capture_output=True,
|
||||||
return lines[-1] if lines else "⚠️ No LTC signal"
|
text=True
|
||||||
|
)
|
||||||
|
|
||||||
|
lines = result.stdout.strip().splitlines()
|
||||||
|
ltc_lines = [line for line in lines if line and line[0].isdigit()]
|
||||||
|
|
||||||
|
return ltc_lines[-1] if ltc_lines else "⚠️ No LTC decoded"
|
||||||
|
|
||||||
|
finally:
|
||||||
|
os.remove(wav_path)
|
||||||
|
|
||||||
def main(stdscr):
|
def main(stdscr):
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
|
|
@ -32,12 +41,12 @@ def main(stdscr):
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
|
|
||||||
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
stdscr.addstr(1, 2, "🌀 NTP Timeturner Status")
|
||||||
stdscr.addstr(3, 4, "Reading LTC from audio device...")
|
stdscr.addstr(3, 4, "Reading LTC from default audio input...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ltc_timecode = read_ltc()
|
ltc_timecode = read_ltc()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
ltc_timecode = f"Error: {e}"
|
ltc_timecode = f"❌ Error: {e}"
|
||||||
|
|
||||||
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {ltc_timecode}")
|
stdscr.addstr(5, 6, f"🕰️ LTC Timecode: {ltc_timecode}")
|
||||||
|
|
||||||
|
|
@ -45,9 +54,9 @@ def main(stdscr):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Pre-flight checks
|
# Pre-flight check
|
||||||
if not shutil.which("ltcdump") or not shutil.which("ffmpeg"):
|
if not shutil.which("ltcdump") or not shutil.which("ffmpeg"):
|
||||||
print("❌ Required tools not found (ltcdump, ffmpeg). Install and retry.")
|
print("❌ Required tools not found (ltcdump or ffmpeg). Install them and retry.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
curses.wrapper(main)
|
curses.wrapper(main)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue