refactor code

This commit is contained in:
vaguesyntax
2025-10-26 14:04:52 +03:00
parent b137feac16
commit 496225ab9d
2 changed files with 40 additions and 44 deletions
@@ -1,10 +1,11 @@
#!/bin/bash
MONITOR_SOURCE="alsa_output.pci-0000_00_1f.3.analog-stereo.monitor"
## can be added manually if not chosen automatically with running this on terminal 'pw-cli list-objects | grep node.name'
MONITOR_SOURCE=$(pactl list short sources 2>/dev/null | grep -m1 monitor | awk '{print $2}' || true)
# Default değerler
INTERVAL=5
TOTAL_DURATION=30
MIN_VALID_RESULT_LENGTH=300
while getopts "i:t:" opt; do
case $opt in
@@ -22,7 +23,7 @@ while true; do
ELAPSED=$((CURRENT_TIME - START_TIME))
if (( ELAPSED >= TOTAL_DURATION )); then
echo "Total duration reached. Exiting."
echo "Total duration reached, no music recognized."
exit 0
fi
@@ -35,7 +36,7 @@ while true; do
RESULT=$(songrec audio-file-to-recognized-song "$TMP_FILE" 2>/dev/null || true)
rm -f "$TMP_FILE"
if [ -n "$RESULT" ] && [ ${#RESULT} -gt 300 ]; then
if [ -n "$RESULT" ] && [ ${#RESULT} -gt $MIN_VALID_RESULT_LENGTH ]; then
echo "$RESULT"
exit 0
fi