#!/bin/bash
lastline="unique.$$.$RANDOM"
while : ; do
    acpi | grep -Po '\d+%'
    sleep 1
done | while read gline; do  # eliminate glitches where we see the wrong reading once
    if [[ "$gline" != "$glitchline" ]]; then
        : do nothing
    else
        echo "$gline"
    fi
    glitchline=$gline
done | while read line; do  # unbuffered uniq because uniq has no -u
    if [[ "$line" != "$lastline" ]]; then
        echo "$line"
        lastline=$line
    fi
done | espeak
