Skip to content

Instantly share code, notes, and snippets.

@adde88
Last active June 5, 2025 15:00
Show Gist options
  • Select an option

  • Save adde88/09e51b527915684b39deb3e3b0fe54f4 to your computer and use it in GitHub Desktop.

Select an option

Save adde88/09e51b527915684b39deb3e3b0fe54f4 to your computer and use it in GitHub Desktop.

Revisions

  1. adde88 revised this gist Jun 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fm_transmit.sh
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ INPUT_FILE="$1"
    FREQ="$2"

    # Constants
    PIFMADV_PATH="/root/PiFmAdv"
    PIFMADV_PATH="/root/PiFmAdv/src"
    PIFM_EXEC="$PIFMADV_PATH/pi_fm_adv"
    TMP_WAV="/tmp/tmp_fm_audio.wav"

  2. adde88 revised this gist Jun 5, 2025. No changes.
  3. adde88 revised this gist Jun 5, 2025. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions fm_transmit.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    #!/bin/bash
    # Author: Andreas Nilsen
    # Email: [email protected]
    # Github: https://www.github.com/adde88
    # License: GPL-3

    # Check arguments
    if [[ $# -ne 2 ]]; then
  4. adde88 created this gist Jun 5, 2025.
    63 changes: 63 additions & 0 deletions fm_transmit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    #!/bin/bash

    # Check arguments
    if [[ $# -ne 2 ]]; then
    echo "Usage: $0 /path/to/file.{wav,mp3,m4a,ogg} frequency_in_MHz"
    echo "Example: $0 /home/pi/audio.mp3 100.1"
    exit 1
    fi

    # Input arguments
    INPUT_FILE="$1"
    FREQ="$2"

    # Constants
    PIFMADV_PATH="/root/PiFmAdv"
    PIFM_EXEC="$PIFMADV_PATH/pi_fm_adv"
    TMP_WAV="/tmp/tmp_fm_audio.wav"

    # Check PiFmAdv binary
    if [[ ! -f "$PIFM_EXEC" ]]; then
    echo "Error: pi_fm_adv not found at $PIFM_EXEC"
    exit 2
    fi

    # Check input file
    if [[ ! -f "$INPUT_FILE" ]]; then
    echo "Error: Input file $INPUT_FILE not found"
    exit 3
    fi

    # Get file extension (lowercased)
    EXT="${INPUT_FILE##*.}"
    EXT="${EXT,,}"

    # Handle file conversion if needed
    case "$EXT" in
    wav)
    FINAL_FILE="$INPUT_FILE"
    ;;
    mp3|m4a|ogg)
    echo "[*] Converting $EXT to WAV..."
    ffmpeg -y -i "$INPUT_FILE" -ar 22050 -ac 1 "$TMP_WAV" >/dev/null 2>&1
    if [[ ! -f "$TMP_WAV" ]]; then
    echo "Error: Failed to convert to WAV."
    exit 4
    fi
    FINAL_FILE="$TMP_WAV"
    ;;
    *)
    echo "Error: Unsupported file format '$EXT'. Supported: wav, mp3, m4a, ogg"
    exit 5
    ;;
    esac

    # Transmit using PiFmAdv
    echo "[*] Starting FM transmission on $FREQ MHz..."
    sudo "$PIFM_EXEC" -f "$FREQ" -music "$FINAL_FILE"

    # Cleanup if temporary file was used
    if [[ "$FINAL_FILE" == "$TMP_WAV" ]]; then
    echo "[*] Cleaning up temporary WAV file..."
    rm -f "$TMP_WAV"
    fi