Skip to content

Commit 5e81d6f

Browse files
mldangeloclaude
andcommitted
feat(msg): add text-to-speech for received messages
Received messages are now spoken aloud via macOS `say` by default. This applies to `msg read` and `msg listen` commands. Users can toggle with `crab msg say on/off`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f59e273 commit 5e81d6f

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/crabcode

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5468,6 +5468,17 @@ msg_set() {
54685468
jq --arg v "$value" ".$field = \$v" "$MSG_CONFIG_FILE" > "$tmp" && mv "$tmp" "$MSG_CONFIG_FILE"
54695469
}
54705470

5471+
# Speak a received message via macOS say (runs in background)
5472+
msg_say() {
5473+
local from="$1"
5474+
local text="$2"
5475+
local say_enabled=$(msg_get "say")
5476+
# Default to enabled if not set
5477+
if [ "$say_enabled" != "false" ] && command_exists say; then
5478+
say "$from said $text" &
5479+
fi
5480+
}
5481+
54715482
# Append to local message log
54725483
msg_log() {
54735484
local direction="$1" # > or <
@@ -5837,6 +5848,7 @@ msg_read() {
58375848
local time_str=$(date -r "${ts%.*}" '+%H:%M' 2>/dev/null || echo "??:??")
58385849
echo -e " ${GRAY}[${time_str}]${NC} ${CYAN}@${from}${NC}: ${text}"
58395850
msg_log "<" "$from" "$text"
5851+
msg_say "$from" "$text"
58405852
done
58415853
echo ""
58425854
}
@@ -5865,6 +5877,7 @@ msg_listen() {
58655877
local time_str=$(date -r "${ts%.*}" '+%H:%M' 2>/dev/null || echo "??:??")
58665878
echo -e " ${GRAY}[${time_str}]${NC} ${CYAN}@${from}${NC}: ${text}"
58675879
msg_log "<" "$from" "$text"
5880+
msg_say "$from" "$text"
58685881
done
58695882
# Update last_ts to the latest message timestamp
58705883
local new_ts
@@ -5915,6 +5928,7 @@ show_msg_help() {
59155928
echo " crab msg read 2h Check inbox (last 2 hours)"
59165929
echo " crab msg listen Live stream (Ctrl+C to stop)"
59175930
echo " crab msg history View local message log"
5931+
echo " crab msg say on/off Toggle text-to-speech (default: on)"
59185932
echo ""
59195933
}
59205934

@@ -5941,6 +5955,22 @@ handle_msg_command() {
59415955
"history"|"log")
59425956
msg_history "${2:-20}"
59435957
;;
5958+
"say")
5959+
local toggle="${2:-}"
5960+
case "$toggle" in
5961+
"on") msg_set "say" "true"; success "Text-to-speech enabled" ;;
5962+
"off") msg_set "say" "false"; success "Text-to-speech disabled" ;;
5963+
*)
5964+
local current=$(msg_get "say")
5965+
if [ "$current" = "false" ]; then
5966+
echo "Text-to-speech: off"
5967+
else
5968+
echo "Text-to-speech: on (default)"
5969+
fi
5970+
echo " crab msg say on/off"
5971+
;;
5972+
esac
5973+
;;
59445974
"status"|"info")
59455975
msg_relay_info
59465976
;;

0 commit comments

Comments
 (0)