forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisakanet_voice_hook.sh
More file actions
executable file
·61 lines (53 loc) · 1.81 KB
/
Copy pathmisakanet_voice_hook.sh
File metadata and controls
executable file
·61 lines (53 loc) · 1.81 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
#!/bin/bash
# MisakaNet Voice Hook — plays audio prompts when MCP tools return voice hints.
#
# Usage in Claude Code settings.json:
# "PostToolUse": [{
# "hooks": [{
# "type": "command",
# "command": "/path/to/MisakaNet/scripts/misakanet_voice_hook.sh"
# }]
# }]
#
# The hook reads JSON from stdin (MCP tool result) and plays the
# corresponding MP3 from docs/assets/voice/ via afplay (macOS).
set -euo pipefail
VOICE_DIR="$(cd "$(dirname "$0")/../docs/assets/voice" && pwd)"
# Read stdin (tool result JSON)
INPUT=$(cat)
# Extract voice field — silent exit if missing
VOICE=$(echo "$INPUT" | python -c "
import sys, json
try:
data = json.load(sys.stdin)
print(data.get('voice', ''))
except:
pass
" 2>/dev/null)
[ -z "$VOICE" ] && exit 0
# Map voice name to file
case "$VOICE" in
connect-success) FILE="$VOICE_DIR/connect-success.mp3" ;;
pair-success) FILE="$VOICE_DIR/pair-success.mp3" ;;
lesson-found) FILE="$VOICE_DIR/lesson-found.mp3" ;;
failure-warning) FILE="$VOICE_DIR/failure-warning.mp3" ;;
*) exit 0 ;;
esac
[ -f "$FILE" ] || exit 0
# Play audio (non-blocking, suppress errors from headless environments)
if command -v afplay &>/dev/null; then
# macOS
afplay "$FILE" &>/dev/null &
elif command -v aplay &>/dev/null; then
# Linux (ALSA)
aplay "$FILE" &>/dev/null &
elif command -v paplay &>/dev/null; then
# Linux (PulseAudio)
paplay "$FILE" &>/dev/null &
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
# Windows (Git Bash / MSYS2)
powershell -Command "Start-Process -FilePath '$FILE' -WindowStyle Hidden" &>/dev/null &
elif command -v powershell.exe &>/dev/null; then
# Windows (WSL)
powershell.exe -Command "Start-Process -FilePath '$(wslpath -w "$FILE")' -WindowStyle Hidden" &>/dev/null &
fi