Skip to content

Using audioplayer.php

Aaron Gershman edited this page Sep 19, 2023 · 2 revisions

audioplayer.php is a quick way to get a web interface to the locally saved media files generated by your Trunk Recorder. It makes it easy to see what your system is recording and test performance prior to uploading to another service such as OpenMHz.

Configuring

audioplayer.php should generally work out of the box however it does require the correct paths to the media files in order to be able to index them. If you aren't encoding files to AAC/.m4a files (which happens automatically if you are uploading to OpenMHz or Broadcastify Calls), you may need to configure encoding or set the audioplayer to serve .wav files. audioplayer.php also looks for files in certain locations so you may have to adjust those paths if needed.

Using .m4a files

Trunk Recorder generates nice normalized .m4a files for upload to the online services. These files are smaller than the initially generated wavfiles and generally sound better because sox normalized the audio. However, if you aren't uploading to a service these files won't be created. We can however use a modified copy of the encode-upload.sh. This will require sox and fdkaac installed. If you are already set to upload to OpenMhz or Broadcastify Calls you do not need to do this since the system is already creating these files.

#! /bin/bash
echo "Encoding: $1" 
filename="$1"
basename="${filename%.*}"
mp4encoded="$basename.m4a"
eval "nice -n 19 sox $filename -t wav - --norm=-3 | nice -n 19 fdkaac --silent --ignorelength -b 8000 -o $mp4encoded -"

You can save this script as encode-upload.sh in the trunk-recorder directory and add the following to your config right after configuring your shortname:

uploadScript: encode-upload.sh

Now Trunk Recorder will generate the same .m4a files it would to upload to the online services.

Using the .wav files

If you're just testing and can give up the .m4a files for a moment, it's easier / faster to just change audioplayer.php to serve the .wav files. Open up audioplayer.php in your favorite text editor and change line 2 from .m4a to .wav. These files won't be audio normalized but are created by default.

<?php
$FileType = '.m4a'; #Change to .wav to index .wav files

File locations

audioplayer.php is setup to work with the present "default" configuration for Trunk Recorder. That has config.json in the main trunk-recorder directory, the ChanList.csv files in the main directory and the files organized by system in the media directory (however audioplayer will dervide the media directory from wherever it it set in config.json).

trunk-recorder
├── audioplayer.php
├── ChanList.csv
├── config.json
└── media/

If this changes (as it does somewhat with docker), you have to symlink or change audioplayer to work. For docker installs, we will do that with a docker-compose below.

Running using native php

In terms of getting up quickly, if php is installed natively on the system you can simple run it's integrated server and be up and running at http://localhost:8080/audioplayer.php

php -S 127.0.0.1 8080

If you run from inside of the trunk-recorder directory and your path's are set, you should be able to open a webpage and view your recordings.

Running when using Dockerized Trunk Recorder

The Dockerized trunk-recorder has a few advantages over the standard Trunk Recorder install. However it does place certain files in different locations relative to config.json. Since audioplayer looks at config.json to determine the paths of the media files, we have to adjust in order to make those files discoverable. Fortunately, we can easily do that with docker-compose. The paths of this docker compose assume you're running trunk-recorder-docker with the media directory mounted and that you'll run trunk-player-docker in a directory next to it. You can certainly adjust path's to your desired location.

trunk-recorder-docker
├── ChanList.csv
├── config/
│   ├── config.json
├── docker-compose.yml
├── Dockerfile
└── media/
trunk-player-docker
├── docker-compose.yml
├── index.php
└── site.conf

docker-compose.yml

version:                '3'

services:
    web:
        image:          nginx
        container_name: trunk-player-nginx
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./index.php:/www/index.php:ro
            - ../trunk-recorder-docker/media:/www/app/media:ro
            - ./site.conf:/etc/nginx/conf.d/default.conf:ro
        restart: unless-stopped
    php:
        image:          php-fpm
        container_name: trunk-player-php
        volumes:
            - ./index.php:/www/index.php:ro
            - ../trunk-recorder-docker/media:/app/media:ro # The www is intentionally omitted here.
            - ../trunk-recorder-docker/config/config.json:/www/config.json:ro
            - ../trunk-recorder-docker/ChanList.csv:/www/ChanList.csv:ro
        restart: unless-stopped
        environment:
            - TZ=America/New_York

And site.conf (nginx's configuration file)

server {
    listen 80;
    index index.php index.html;
    server_name localhost;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /www;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\. {
        deny all;
    }

    location /app/media {
        autoindex on;
    }
}