Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HELP] Trunk-Recorder sending to Liquidsoap socket but Liquidsoap not doing anything #1004

Open
jared-bloomer opened this issue Feb 24, 2025 · 0 comments

Comments

@jared-bloomer
Copy link

jared-bloomer commented Feb 24, 2025

Problem

This is running in Docker

I have trunk-recorder running with an upload-liquidsoap.py, but liquidsoap isn't doing anything with the wav file being sent. I am not getting any audio on my broadcastify feed even though it is connected and online. If there is any additional information needed, please let me know.

Logs

trunk-recorder  | [2025-02-24 02:54:55.036050] (info)   [hcps]  1055C   TG:        417  Freq: 851.837500 MHz    C        Running upload script: /app/upload-liquidsoap.py /app/media/hcps/2025/2/24/417-1740365692_851837500.0-call_1055.wav /app/media/hcps/2025/2/24/417-1740365692_851837500.0-call_1055.json /app/media/hcps/2025/2/24/417-1740365692_851837500.0-call_1055.m4a
trunk-recorder  | connecting to /var/run/liquidsoap/hcps.sock
trunk-recorder  | sending "request.queue_0.push annotate:title='':/app/media/hcps/2025/2/24/417-1740365692_851837500.0-call_1055.wav"
trunk-recorder  | closing socket
liquidsoap      | 2025/02/24 02:55:03 [clock.generic:2] We must catchup 0.37 seconds!

upload-liquidsoap.py

#!/usr/bin/python3
#
# for docker trunk recorder user root to run/execute this, set permissions on this file to 744
#
import socket
import sys
import os
import time
import re
import json
import shutil

delete = False #delete files after stream or not

filepath = sys.argv[1]
jsonpath = os.path.splitext(filepath)[0] + ".json"
#while tr v4+ does pass json path as arg, will still generate it this way for v3 compat

with open(jsonpath, 'r') as f:
  jsonData = json.load(f)
talkgroup = jsonData['talkgroup']


##############################
#archive unknown TG json/wav for later research, check /app/media/UNKNOWN/ exists, requires import shutil
#could just set delete = False, but its easier to check if all put in one folder
if jsonData['talkgroup_tag'] == '-':
    shutil.copy(filepath, '/app/media/UNKNOWN/'+ os.path.basename(filepath))
    jsonData['talkgroup_tag'] = str(talkgroup)+' Unknown'
##############################

# Create a UDS socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

# Connect the socket to the port where the server is listening
# The following is example login to determine which stream to choose, customise as need

if 'SYSTEM_NAME' in filepath:
    with open('TALKGROUPS.list') as file:
        talkgroups= file.readlines()

    if talkgroup in talkgroups:
        server_address = '/var/run/liquidsoap/hcps.sock'
    else:
        server_address = '/var/run/liquidsoap/hcps.sock'
else:
    server_address = '/var/run/liquidsoap/hcps.sock'

print ('connecting to %s' % server_address)

try:
        sock.connect(server_address)
except socket.error as msg:
        print('socket error')
        print(msg)
        sys.exit(1)

try:
    # Send data
    metaCommand = "annotate:title='"+jsonData['talkgroup_tag']+"':"
    if(delete):
        deleteCommand = "tmp:"
    else:
        deleteCommand = ""

    message = 'request.queue_0.push {0}{1}{2}\n\r'.format(metaCommand,deleteCommand,filepath)
    #annotate: manually sets meta alpha tags from talkgroups csv and tmp: sets LS to delete after stream
    print('sending "%s"' % message.strip())
    sock.sendall(message.encode())

# useful for debugging by print liquidsoap socket response messages
#    while True:
#        data = sock.recv(16)
#        if (re.search('END', data.decode())):
#           break
#        print(data.decode())

finally:
    print('closing socket')
    quit = "exit\r\n"
    sock.send(quit.encode()) #to avoid disconnect without goodbye message, though not necessary :)
    time.sleep(0.5) #to avoid disconnect without goodbye message, though not necessary :)
    sock.close()
    os.remove(jsonpath)
    if delete:
        os.remove(jsonpath)

docker-compose.yaml

services:
  liquidsoap:
    image: savonet/liquidsoap:v2.3.1
    container_name: liquidsoap
    restart: always
      #depends_on:
      #  - trunk-recorder
    privileged: true
    user: 0:0
    command:
      - /etc/liquidsoap/stream0.liq
    volumes:
      - ./trunk-recorder/media:/app/media
      - ./liquidsoap:/etc/liquidsoap
      - /var/run/liquidsoap:/var/run/liquidsoap
    logging:
      options:
        {'max-size':'1m', 'max-file':'5'}

  trunk-recorder:
    image: robotastic/trunk-recorder:5.0.1
    container_name: trunk-recorder
    restart: always
    command: ["trunk-recorder","--config=/app/config.json"]
    volumes:
      - ./trunk-recorder:/app
      - /var/run/dbus:/var/run/dbus
      - /var/run/avahi-daemon/socket:/var/run/avahi-daemon/socket
      - /var/run/liquidsoap:/var/run/liquidsoap
    devices:
      - "/dev/bus/usb:/dev/bus/usb:rwm"
    logging:
      options:
        {'max-size':'1m', 'max-file':'5'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant