Ubuntu -- TrunkRecorder -- Liquidsoap -- Almost there!

Status
Not open for further replies.

ervfc288

Member
Feed Provider
Joined
Jan 22, 2015
Messages
85
Location
Culpeper, VA
I am following this wiki post (Streaming with Trunk Recorder and Liquidsoap - The RadioReference Wiki) and my goals are as follows:

1) Use an airspy device to capture every talkgroup on a specified system using Trunk Recorder. (Done)
2) Connect to broadcastify using liquidsoap. (Done)
3) Inject specific talkgroups captured into the liquidsoap stream. (Almost there!)
4) Prove concept and then provide multiple broadcastify streams from a single airspy source by mixing and matching talkgroups as needed and injecting into individual streams.

I've got most everything working as intended and I have a silent feed going. My trouble is with the encode_upload.py script. When I execute it against a certain audio recording, this is what happens. I am not a python guy so I am having trouble tracking down the root cause. It seems MAYBE there isn't logging_config.ini but I don't know where that is supposed to be or anything.. that file doesn't exist on my system. Any help is appreciated.


Code:
jason@rtlsdr:/opt/recorder$ ./encode_upload.py /opt/recorder/archive/albp16/2022/2/20/35280-1645404421_857437500-call_74.wav /opt/recorder/archive/albp16/2022/2/20/35280-1645404421_857437500-call_74.json /opt/recorder/archive/albp16/2022/2/20/35280-1645404421_857437500-call_74.m4a
Traceback (most recent call last):
  File "./encode_upload.py", line 11, in <module>
    fileConfig('logging_config.ini')
  File "/usr/lib/python3.8/logging/config.py", line 71, in fileConfig
    formatters = _create_formatters(cp)
  File "/usr/lib/python3.8/logging/config.py", line 104, in _create_formatters
    flist = cp["formatters"]["keys"]
  File "/usr/lib/python3.8/configparser.py", line 960, in __getitem__
    raise KeyError(key)
KeyError: 'formatters'

Code:
Feb 21 15:23:52 rtlsdr recorder[165330]: [2022-02-21 15:23:52.180233] (info)   [albp16]#011#033[0;34m0C#033[0m #011 Running upload script: ./encode_upload.py /opt/recorder/archive/albp16/2022/2/21/24784-1645474993_857162500-call_0.wav /opt/recorder/archive/albp16/2022/2/21/24784-1645474993_857162500-call_0.json /opt/recorder/archive/albp16/2022/2/21/24784-1645474993_857162500-call_0.m4a
Feb 21 15:23:52 rtlsdr recorder[165330]: [2022-02-21 15:23:52.183383] (info)   Updated Voice Channel source id: 31143 pos: 2304 offset: 0
Feb 21 15:23:52 rtlsdr recorder[165330]: [2022-02-21 15:23:52.183555] (info)   [albp16]#011#033[0;34m1C#033[0m#011TG: #033[35m     30032#033[0m#011Freq: 853.650000 MHz#011Starting new Transmission #011Src ID:  31143
Feb 21 15:23:52 rtlsdr recorder[165955]: Traceback (most recent call last):
Feb 21 15:23:52 rtlsdr recorder[165955]:   File "./encode_upload.py", line 11, in <module>
Feb 21 15:23:52 rtlsdr recorder[165955]:     fileConfig('logging_config.ini')
Feb 21 15:23:52 rtlsdr recorder[165955]:   File "/usr/lib/python3.8/logging/config.py", line 71, in fileConfig
Feb 21 15:23:52 rtlsdr recorder[165955]:     formatters = _create_formatters(cp)
Feb 21 15:23:52 rtlsdr recorder[165955]:   File "/usr/lib/python3.8/logging/config.py", line 104, in _create_formatters
Feb 21 15:23:52 rtlsdr recorder[165955]:     flist = cp["formatters"]["keys"]
Feb 21 15:23:52 rtlsdr recorder[165955]:   File "/usr/lib/python3.8/configparser.py", line 960, in __getitem__
Feb 21 15:23:52 rtlsdr recorder[165955]:     raise KeyError(key)
Feb 21 15:23:52 rtlsdr recorder[165955]: KeyError: 'formatters'

Here is the encode_upload.py

Code:
#!/usr/bin/env python3
import socket
import sys
import os
from subprocess import call
from subprocess import PIPE, run

import logging
from logging.config import fileConfig

fileConfig('logging_config.ini')
logger = logging.getLogger('streamthis')

CSV_FILE="/opt/recorder/ChannelList.csv"
FILE_TO_ENCODE=sys.argv[1]
logger.debug("file to encode: %s", FILE_TO_ENCODE)

def touch(fname, times=None):
    with open(fname, 'a'):
        os.utime(fname, times)

WAV_FILE=os.path.basename(FILE_TO_ENCODE)
logger.debug("WAV_FILE: %s", WAV_FILE)

DIRECTORY=os.path.dirname(FILE_TO_ENCODE)
logger.debug("DIRECTORY: %s", DIRECTORY)

a = WAV_FILE.split('.')
FILENAME = a[0]
logger.debug("FILENAME: %s", FILENAME)

MP3_FILE="{0}/{1}.mp3".format(DIRECTORY, FILENAME)
logger.debug("MP3_FILE: %s", MP3_FILE)

a = FILENAME.split('-')
TALKGROUP = a[0]
logger.debug("TALKGROUP: %s", TALKGROUP)

command = ['/bin/grep', TALKGROUP, CSV_FILE]
result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
#print(result.returncode, result.stdout, result.stderr)
csvline = result.stdout
logger.debug("csvline: %s", csvline)
a = csvline.split(',')
ALPHA, STREAM_LIST = a[3], a[8]
logger.debug("ALPHA: %s", ALPHA)
logger.debug("STREAM_LIST: %s", STREAM_LIST)

if (STREAM_LIST.strip() == ''):
    logger.info("No Stream for [%s] %s", TALKGROUP, ALPHA)
    quit(0)

logger.debug("Calling: %s %s %s %s %s %s %s", "/usr/bin/lame", "--quiet", "--preset", "voice", "--tt", "\"{0}\"".format(ALPHA), FILE_TO_ENCODE)
call(["/usr/bin/lame", "--quiet", "--preset", "voice", "--tt", "\"{0}\"".format(ALPHA), FILE_TO_ENCODE])

if os.path.exists(FILE_TO_ENCODE):
  os.remove(FILE_TO_ENCODE)

streams = STREAM_LIST.split('|')
servers = []

for stream in streams:
    logger.debug(">>>>> %s, %s is in the list", stream, TALKGROUP)
    touch("/tmp/streamthis-{0}-lastrun".format(stream))
    stream_address = "/home/jason/.opam/4.08.0/lib/liquidsoap/var/run/liquidsoap/{0}.sock".format(stream)
    logger.debug("[%s] matched for %s, sending to: %s", TALKGROUP, stream, stream_address)
    servers.append(stream_address)

if len(servers) < 1:
    logger.error("Talkgroup [%s] did not have any streams in the list: %s", TALKGROUP, STREAM_LIST)
    exit(1)

for server_address in servers:
    logger.debug("address: %s", server_address)
    # Create a UDS socket
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

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

    try:
        # Send data
        logger.info('%s %s %s', TALKGROUP, "sending to: ", server_address)
        logger.debug('queue.push {0}\n\r'.format(MP3_FILE))
        message = 'queue.push {0}\n\r'.format(MP3_FILE)
        sock.sendall(message)

        amount_received = 0
        amount_expected = len(message)

        data = sock.recv(16)
        amount_received += len(data)

    finally:
        match = 0
        sock.close()
 
Last edited:

ervfc288

Member
Feed Provider
Joined
Jan 22, 2015
Messages
85
Location
Culpeper, VA
I've been spending a lot of time on this and it looks like I am missing an entire logging config file known as logging_config.ini

Trying to find out who authored the article with very little luck.

Jason
 

xicarusx

Member
Feed Provider
Joined
Oct 2, 2008
Messages
104
Location
Sayre, PA
I've been spending a lot of time on this and it looks like I am missing an entire logging config file known as logging_config.ini

Create a file named logging_config.ini in the project root directory.

Read the following documents on how to add a configuration to the file.
 

ervfc288

Member
Feed Provider
Joined
Jan 22, 2015
Messages
85
Location
Culpeper, VA
Create a file named logging_config.ini in the project root directory.

Read the following documents on how to add a configuration to the file.

thank you for that resource, I’ll start reading :)
 
Status
Not open for further replies.
Top