Adding features to setup

I want to add a feature to my setup page when I sign into my node using Putty. Is that possible?
I want to add a Python script I made to create audio files. Instead of going online and creating a sound file then going somewhere else to convert it to .gsm and then upload to the pi.
I know ASL already has a way to do this but you have to go into the bash shell run it and still have to move the sound file around to the right folder. With my script it ask for user input of what you want to convert into a sound file, then it asks what you want to name the file. After converting it to .wav it converts it to .gsm or .ul and saves the file in /var/lib/asterisk/sounds. I tried the convert_audio.sh but with that, you have to make the .wav file first and then it converts it to the file needed for asterisk.

My script does everything on the pi. No need to transfer files and convert them.

I want to add it to this.

menu

I’m not sure if that is an ASL menu or HamVoIP. In either case you need to polk around and find the menu script. The script will likely be in either /usr/bin, or /usr/sbin, or maybe /usr/local/bin and named asl-menu. Once you find it adding an item should be straight forward for a guy that wrote his own script.

I found it and made my own menu.
Still a work in progress but I am getting a bunch of scripts that are already on the Pi and difficult to find and adding the most useful ones to a menu.

.

would you be willing to distribute this? I would like an easy way to make sound files.
Mike N3IDS

1 Like

To keep it simple many years ago, I used asterisk to record sound files.
This keeps it in native formats without scripting conversion.

I just used it for id, tail mesgs and 1 special one that would just record it to my special sound dir that I would later just rename for whatever function I was building.

But all of that is dependent on using a newly created sound, or, on the fly so to speak.
When you build the function in asterisk extensions.conf, you can do the sweet stuff on a phone/sip connect and keep it off the air and provide a crisp clear recorded message if your mic is good. I had it playback right after recording and gave myself the option to keep or toss and try again.
There is never a bad time to learn the asterisk dial plan. Well documented on the web.

Perhaps an ave to take ?

1 Like

I am making another modified version of it because the script only saves files created in one folder, /var/lib/asterisk/sounds . The Default Asterisk Sounds folder. So I am adding it so the user can save to whatever folder he likes and probably even create a folder to save the new sound files to.

I posted it on Github with installation instructions and how to run the menu once installed. BUT A WORD OF CAUTION I made this on an older image of ASL so if you try it let me know if it works or if it doesn’t. I have another node with a newer version of ASL so I can try to recreate it there in case it doesn’t work.

I am also working on an update script to add to the menu so when I add anything you can just hit update, but have to check more on that as I am not that familiar with GitHub.

After so much back and forth I just left it alone and used the native codecs.

Believe me, I am using an older version of ASL so I don’t have the option to create .gsm files only .ul but I don’t hear a difference from ul to gsm. I had to update ffmpeg and still not able to create gsm but from reading online apparently the codec for gsm is disabled and I have to add it to the PATH so it will be usable.

1 Like

I can only say that I did mine starting with the ACID ver when it was new using Asterisk to record the file in native format.
I do use UL most often or mp3 for interaction of external things.

You can lookup the method of recording using asterisk and you have enough coding under you to figure out the rest i think.

Here is a simple clip of a sub that I used in the dialplan to record/play a tail message.
You should be able to figure the format and run with it. Recorded in WAV and I’m not sure why I used that then, but I’m sure I had a reason. You can specify any native format.

exten => 10,1,Playback(/etc/asterisk/msg/tmsg1) ;play current tmsg1
exten => 10,n,Hangup
exten => 11,1,Playback(please-enter-your&vm-message&after-the-tone) ;record tmsg1
exten => 11,n,Record(/etc/asterisk/msg/tmsg1:wav)
exten => 20,1,Playback(/etc/asterisk/msg/tmsg2) ; play tmsg2
exten => 20,n,Hangup

Straight up as it is you would need to do this from a sip phone or equivalent.
If you use my sneaky way of calling the stanza from a rpt phone patch, you can do it from the radio as well as app_rpt will not natively allow you.
The issue with using the patch to get to it in the dial plan is that you have to hang-up to end it.

Natively on a sipphone you can use the full command set and use silence detection(short) if you enable that as well in modules.conf

I’m sure there are a few tricky things I am forgetting, I have not worked with it in 10 years or more. I am doing something else now.

seems it saves as a “.ul” file
Not familiar with that… how would I get a gsm file?

Ps, where did you find the asl-menu?

.ul is just another sound file. I have compared both the GSM an ul and haven’t noticed a difference but ask will play it regardless.

I have to look at my notes because it took me a while to find the template used and I don’t remember at this moment.

I made a mistake on the first version of the script as I did one before without the menu and stuff and it was only for making sound files from text and that script checked the Pi for ffmpeg, pip and THAT’S and would install them if they were not present. I then started working on the menu and redid the script and because I already had gets, ffmpeg and pip it worked no problem but any new installation would run into trouble as soon as they tried creating a sound file.
It’s fixed now and added another script to modify the global.inc. Have a few more that I will be adding soon.

in the old version of ASL there was something called Dialog and that’s what was used for the menu.

What I meant was what directory?
Mike

I don’t know what folder it will be. Dialog is used by python to make the menu boxes and questions. Here is a sample menu in Python, you can make a file named test.py copy and past this code ,make it executable and test it.

#!/usr/bin/env python3

import subprocess

def showinfo(title, message):
    subprocess.run(['dialog', '--msgbox', message, '10', '50'])

def showwarning(title, message):
    subprocess.run(['dialog', '--msgbox', message, '10', '50'])

def showerror(title, message):
    subprocess.run(['dialog', '--msgbox', message, '10', '50'])

def askquestion(title, message):
    result = subprocess.run(['dialog', '--yesno', message, '10', '50'])
    return 'yes' if result.returncode == 0 else 'no'

def askokcancel(title, message):
    result = subprocess.run(['dialog', '--yesno', message, '10', '50'])
    return 'ok' if result.returncode == 0 else 'cancel'

def askyesno(title, message):
    result = subprocess.run(['dialog', '--yesno', message, '10', '50'])
    return 'yes' if result.returncode == 0 else 'no'

def askyesnocancel(title, message):
    result = subprocess.run(['dialog', '--yesnocancel', message, '10', '50'])
    if result.returncode == 1:
        return None
    return 'yes' if result.returncode == 0 else 'no'

def askretrycancel(title, message):
    result = subprocess.run(['dialog', '--yesno', message, '10', '50'])
    return 'retry' if result.returncode == 0 else 'cancel'

if __name__ == "__main__":
    showinfo("Information", "This is an informational message.")
    showwarning("Warning", "This is a warning message.")
    showerror("Error", "This is an error message.")
    print("Question response:", askquestion("Question", "Do you want to proceed?"))
    print("OK/Cancel response:", askokcancel("OK/Cancel", "Do you want to proceed?"))
    print("Yes/No response:", askyesno("Yes/No", "Do you agree?"))
    print("Yes/No/Cancel response:", askyesnocancel("Yes/No/Cancel", "What is your choice?"))
    print("Retry/Cancel response:", askretrycancel("Retry/Cancel", "Do you want to retry?"))

Here is a copy of one I created

#!/bin/bash

# 5/26/2024 WROG208 \ N4ASS
# www.lonewolfsystem.org

show_menu() {
    dialog --clear --backtitle "" \
       --title "WROG208 / N4ASS"\
       --menu "Extras Menu Choose an option:" \
       20 60 10 \
       1 "Script to Make sound files from Text" \
       2 "Script to Make CRON jobs" \
       3 "Script to Update The Database" \
       4 "Script to Current CPU stats" \
       5 "Script to Reboot the Pi" \
       6 "Script to Run the First Time script" \
       7 "Script to Change information in Global.inc" \
       8 "Script to Setup Supermon" \
       9 "Exit" \
       3>&1 1>&2 2>&3
}

confirm_choice() {
    dialog --clear --title "Confirmation" --yesno "Are you sure about what you are doing?" 7 60
    return $?
}

display_info() {
    local choice=$1
    case $choice in
        1)
            dialog --msgbox "This script will use Text to create sound files based on the specified parameters. In English Or Spanish" 7 60
            ;;
        2)
            dialog --msgbox "This script will create CRON jobs to automate tasks. DON'T USE IT IF YOU DON'T KNOW WHAT YOU ARE DOING!!!!" 7 60
            ;;
        3)
            dialog --msgbox "This script will update the database with the latest NODE data. Use when you have the NODE not in the database on your Supermon." 7 60
            ;;
        4)
            dialog --msgbox "This script will tell you the Current CPU stats." 7 60
            ;;
        5)
            dialog --msgbox "This script will Reboot the Pi." 7 60
            ;;
        6)
            dialog --msgbox "This script will run the First Time script that was used to set up the node the first time." 7 60
            ;;
        7)
            dialog --msgbox "This script can change the information on Global.inc. The top portion of your Supermon page" 7 60 
            ;;
        8)
            dialog --msgbox "This script will setup your supermon page" 7 60 
            ;;
        9)
            dialog --msgbox "Goodbye..." 5 40
            exit 0  
            ;;
        *)
            dialog --msgbox "Invalid choice, please select a valid option." 7 60
            ;;
    esac
}

execute_choice() {
    local choice=$1
    case $choice in
        1)
            dialog --infobox "Running Script to make sound files..." 5 50
            gsmbi.py || { dialog --msgbox "An error occurred while running gsmbi.py" 7 60; sleep 5; return 1; }
            ;;
        2)
            dialog --infobox "Running Script to make CRON jobs..." 5 50
            cronJ.sh || { dialog --msgbox "An error occurred while running cronJ.sh" 7 60; sleep 5; return 1; }
            ;;
        3)
            dialog --infobox "Running Script to update the database..." 5 50
            astdb.php || { dialog --msgbox "An error occurred while running astdb.php" 7 60; sleep 5; return 1; }
            ;;
        4)
            dialog --infobox "Running Script Current CPU stats..." 5 50
            cpu_stats.sh || { dialog --msgbox "An error occurred while running cpu_stats.sh" 7 60; sleep 5; return 1; }
            ;;
        5)
            dialog --infobox "Running Script to Reboot the Pi..." 5 50
            reboot.sh || { dialog --msgbox "An error occurred while running reboot.sh" 7 60; sleep 5; return 1; }
            ;;
        6)
            dialog --infobox "Running Script First Time..." 5 50
            firsttime.sh || { dialog --msgbox "An error occurred while running firsttime.sh" 7 60; sleep 5; return 1; }
            ;;
        7)
            dialog --infobox "Running Script To Change the information on global.inc" 5 50
            global.sh || { dialog --msgbox "An error occurred while running global.sh" 7 60; sleep 5; return 1; }
            ;;
        8)
            dialog --infobox "Running Script To Set up your Supermon Page" 5 50
            supermon.setup.sh || { dialog --msgbox "An error occurred while running supermon.setup.sh" 7 60; sleep 5; return 1; } 
            ;;
        9)
            dialog --infobox "Goodbye..." 5 40
            exit 0 
            ;;
        *)
            dialog --msgbox "Invalid choice, please select a valid option." 7 60
            ;;
    esac
}

while true; do
    CHOICE=$(show_menu)
    if [[ -n $CHOICE ]]; then
        display_info $CHOICE
        if [[ $CHOICE -eq 2 ]]; then
            if confirm_choice; then
                execute_choice $CHOICE
            else
                dialog --msgbox "Returning to menu..." 5 40
            fi
        else
            execute_choice $CHOICE
        fi
    else
        clear
        exit 0
    fi
done