-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect-mic.sh
More file actions
executable file
·64 lines (56 loc) · 1.67 KB
/
select-mic.sh
File metadata and controls
executable file
·64 lines (56 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Microphone selection helper
# Resolve symlinks to find real script directory
SCRIPT_PATH="${BASH_SOURCE[0]}"
while [[ -L "$SCRIPT_PATH" ]]; do
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
SCRIPT_PATH="$(readlink "$SCRIPT_PATH")"
[[ "$SCRIPT_PATH" != /* ]] && SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_PATH"
done
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
ENV_FILE="$SCRIPT_DIR/.env"
ICON_DIR="$SCRIPT_DIR/icons"
source "$ENV_FILE"
# Get available microphones (non-monitor sources)
get_mics() {
pactl list sources short | grep -v monitor | awk '{print $2}'
}
# Build menu items
mics=$(get_mics)
current_mic="${MIC_SOURCE:-}"
menu_items=""
# Add default option first
if [[ -z "$current_mic" ]]; then
menu_items="TRUE\n(default)\n"
else
menu_items="FALSE\n(default)\n"
fi
for mic in $mics; do
if [[ "$mic" == "$current_mic" ]]; then
menu_items="${menu_items}TRUE\n${mic}\n"
else
menu_items="${menu_items}FALSE\n${mic}\n"
fi
done
# Show selection dialog
selected=$(echo -e "$menu_items" | yad --list \
--title="Select Microphone" \
--column="":RD \
--column="Microphone" \
--radiolist \
--width=500 \
--height=300 \
--print-column=2 \
--separator="" \
--center \
2>/dev/null)
if [[ -n "$selected" ]]; then
# Update .env file
if [[ "$selected" == "(default)" ]]; then
sed -i 's/^MIC_SOURCE=.*/MIC_SOURCE=""/' "$ENV_FILE"
notify-send "Voice Input" "Using default microphone" -i "$ICON_DIR/idle.svg"
else
sed -i "s/^MIC_SOURCE=.*/MIC_SOURCE=\"$selected\"/" "$ENV_FILE"
notify-send "Voice Input" "Microphone: $selected" -i "$ICON_DIR/idle.svg"
fi
fi