Speech to text failover system (with proof of concept script)

wyoming is a process intense system and my language Dutch does not work properly with a small model. I dont have a 24/7 system that responds within 2 seconds.

Could a failover system voor speech detection be created. Where a list of services is selected with a priority and the best online is selected.

This can be used for 2 scenarios.

  1. local failover for nabucasa cloud system. So that you dont go back to the stoneage when the inet is down.
  2. local none 24/7 preferred system. You got a nice laptop or a gamer pc that might be on but isnt a 24/7 system so you need a fail over.

The great thing of this because the lower priority are probably using a smaller model. That could give translation errors.
Because you have a higher resolution result. the failover system can learn from consisted translation errors by adding those to some translation table to the right text.

This way the whole Voice experience will improve. Because the user will have the fastest speech to text available and when the lower system is used this is backed with translation of your most used speech commands.

Here a proof of concept for just changing the IP address using duckdns.
Make sure all wyoming services use the same Port.

#!/bin/bash 

DOMAIN=wyoming
TOKEN=123456

# List of potential ip's resolved. 1st one that pings is used.
IP_STRING="192.168.5.230 10.209.212.9 192.168.5.5 192.168.5.1"

# Convert the IP string into an array
IFS=' ' read -r -a IP_ARRAY <<< "$IP_STRING"

# Initialize a variable to store the previous IP address
PREVIOUS_IP=""

while true; do

    # Initialize a variable to check if the IP has changed
    IP_CHANGED=false

    # Iterate over each IP address in the array
    for IP_ADDRESS in "${IP_ARRAY[@]}"; do
        # Ping the IP address with only one ICMP packet and suppress output
        if ping -c 1 -W 1 "$IP_ADDRESS" &> /dev/null; then
            # If ping is successful, assign the IP address to the $IP variable
            IP="$IP_ADDRESS"
            # Check if the IP has changed
            if [ "$IP" != "$PREVIOUS_IP" ]; then
                IP_CHANGED=true
                PREVIOUS_IP="$IP"  # Update the previous IP
            fi
            # Exit the loop after finding the first IP address
            break
        fi
    done

    # If the IP has changed, execute the curl command
    if [ "$IP_CHANGED" = true ]; then
        echo "Found IP: $IP"
        echo "Executing curl command with new IP: $IP"
        if curl_output=$(curl -s -k "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ip=$IP"); then
          echo "Curl command successful."
        else
          echo "Curl command failed. Waiting 30 seconds before retrying"
          PREVIOUS_IP="offline"
          sleep 25
        fi
    fi

    # If no IP address is found, print a message
    if [ -z "$IP" ]; then
        echo "No IP address found in the list."
    else 
        echo "$IP is active."
    fi

    sleep 5
done