<commit_before>##################
# Main Functions #
##################

# How to install sox?
# MacOSX: http://sourceforge.net/projects/sox/files/sox/14.4.2/
# Linux: "sudo apt-get install sox"

PLAY () { # PLAY () {} Play audio file $1
    play -V1 -q $1
}

RECORD () { # RECORD () {} record microhphone to audio file $1 when sound is detected until silence
    #$verbose && local quiet='' || local quiet='-q'
    rec -V1 -q -r 16000 -c 1 -b 16 -e signed-integer --endian little $1 silence 1 $min_noise_duration_to_start $min_noise_perc_to_start 1 $min_silence_duration_to_stop $min_silence_level_to_stop trim 0 $max_noise_duration_to_kill
    if [ "$?" -ne 0 ]; then
        echo "ERROR: rec command failed"
        exit 1
    fi
}

LISTEN_COMMAND () {
    while true; do
        settimeout 10 RECORD "$audiofile"
        duration=`sox $audiofile -n stat 2>&1 | sed -n 's#^Length[^0-9]*\([0-9]*\).\([0-9]\)*$#\1\2#p'`
        $verbose && echo "DEBUG: speech duration was $duration (10 = 1 sec)"
        if [ -z "$duration" ]; then
            $verbose && echo "DEBUG: timeout, end of conversation" || printf '.'
            PLAY beep-low.wav
            sleep 1 # BUG here despite timeout mic still busy can't rec again...
            bypass=false
            order='' # clean previous order
            break 2
        elif [ "$duration" -gt 40 ]; then
            $verbose && echo "DEBUG: too long for a command (max 4 secs), ignoring..." || printf '#'
            continue
        else
            break
        fi
    done
}

LISTEN_TRIGGER () {
    while true; do
        RECORD "$audiofile"
        duration=`sox $audiofile -n stat 2>&1 | sed -n 's#^Length[^0-9]*\([0-9]*\).\([0-9]\)*$#\1\2#p'`
        $verbose && echo "DEBUG: speech duration was $duration (10 = 1 sec)"
        if [ "$duration" -lt 2 ]; then
            $verbose && echo "DEBUG: too short for a trigger (min 0.2 max 1.5 sec), ignoring..." || printf '-'
            continue
        elif [ "$duration" -gt 20 ]; then
            $verbose && echo "DEBUG: too long for a trigger (min 0.5 max 1.5 sec), ignoring..." || printf '#'
            sleep 1 # BUG 
            continue
        else
            break
        fi
    done
}

LISTEN () {
    $bypass && LISTEN_COMMAND || LISTEN_TRIGGER
    $verbose && PLAY "$audiofile"
}

TTS () { # TTS () {} Speaks text $1
    $tts_engine'_TTS' "$1"
}
<commit_msg>help messages<commit_after>##################
# Main Functions #
##################

# How to install sox?
# MacOSX: http://sourceforge.net/projects/sox/files/sox/14.4.2/
# Linux: "sudo apt-get install sox"

PLAY () { # PLAY () {} Play audio file $1
    play -V1 -q $1
    if [ "$?" -ne 0 ]; then
        echo "ERROR: play command failed"
        echo "HELP: Verify your speaker in Settings > Audio > Speaker"
        exit 1
    fi
}

RECORD () { # RECORD () {} record microhphone to audio file $1 when sound is detected until silence
    #$verbose && local quiet='' || local quiet='-q'
    rec -V1 -q -r 16000 -c 1 -b 16 -e signed-integer --endian little $1 silence 1 $min_noise_duration_to_start $min_noise_perc_to_start 1 $min_silence_duration_to_stop $min_silence_level_to_stop trim 0 $max_noise_duration_to_kill
    if [ "$?" -ne 0 ]; then
        echo "ERROR: rec command failed"
        echo "HELP: Verify your mic in Settings > Audio > Mic"
        exit 1
    fi
}

LISTEN_COMMAND () {
    while true; do
        settimeout 10 RECORD "$audiofile"
        duration=`sox $audiofile -n stat 2>&1 | sed -n 's#^Length[^0-9]*\([0-9]*\).\([0-9]\)*$#\1\2#p'`
        $verbose && echo "DEBUG: speech duration was $duration (10 = 1 sec)"
        if [ -z "$duration" ]; then
            $verbose && echo "DEBUG: timeout, end of conversation" || printf '.'
            PLAY beep-low.wav
            sleep 1 # BUG here despite timeout mic still busy can't rec again...
            bypass=false
            order='' # clean previous order
            break 2
        elif [ "$duration" -gt 40 ]; then
            $verbose && echo "DEBUG: too long for a command (max 4 secs), ignoring..." || printf '#'
            continue
        else
            break
        fi
    done
}

LISTEN_TRIGGER () {
    while true; do
        RECORD "$audiofile"
        duration=`sox $audiofile -n stat 2>&1 | sed -n 's#^Length[^0-9]*\([0-9]*\).\([0-9]\)*$#\1\2#p'`
        $verbose && echo "DEBUG: speech duration was $duration (10 = 1 sec)"
        if [ "$duration" -lt 2 ]; then
            $verbose && echo "DEBUG: too short for a trigger (min 0.2 max 1.5 sec), ignoring..." || printf '-'
            continue
        elif [ "$duration" -gt 20 ]; then
            $verbose && echo "DEBUG: too long for a trigger (min 0.5 max 1.5 sec), ignoring..." || printf '#'
            sleep 1 # BUG 
            continue
        else
            break
        fi
    done
}

LISTEN () {
    $bypass && LISTEN_COMMAND || LISTEN_TRIGGER
    $verbose && PLAY "$audiofile"
}

TTS () { # TTS () {} Speaks text $1
    $tts_engine'_TTS' "$1"
}

{'fraction_non_alphanumeric': 0.15623746490172483, 'fraction_numerical': 0.028479743281187325, 'mean_word_length': 2.1364779874213835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4183911', 'n_tokens_mistral': 1705, 'n_tokens_neox': 1603, 'n_words': 527}