From af834a46192c03aae87457e1d7b141ca1e718fee Mon Sep 17 00:00:00 2001 From: David Chen Date: Thu, 28 Aug 2025 18:20:16 -0700 Subject: [PATCH] global claude code voice mode --- .gitignore | 3 +++ README.md | 17 ++++++++++----- README_cn.md | 17 ++++++++++----- claude/scripts/voice-off.sh | 11 ---------- claude/scripts/voice-on.sh | 11 ---------- claude/settings.json | 2 +- raycast-scripts/claude-code-voice-toggle.sh | 23 +++++++++++++++++++++ raycast-scripts/stop-voice-tts.sh | 15 ++++++++++++++ 8 files changed, 66 insertions(+), 33 deletions(-) delete mode 100755 claude/scripts/voice-off.sh delete mode 100755 claude/scripts/voice-on.sh create mode 100755 raycast-scripts/claude-code-voice-toggle.sh create mode 100755 raycast-scripts/stop-voice-tts.sh diff --git a/.gitignore b/.gitignore index dff051f..ea9b958 100755 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,6 @@ yazi/bookmark # Deploy script !/deploy.sh + +# Raycast scripts directory +!/raycast-scripts/ diff --git a/README.md b/README.md index a929998..3884132 100644 --- a/README.md +++ b/README.md @@ -28,11 +28,18 @@ If you need to install Homebrew manually: ### Claude Code Voice Configuration -This config includes a directory-based voice system for Claude Code that uses macOS text-to-speech. +This config includes a global voice system for Claude Code that uses macOS text-to-speech. #### Voice Commands -- `/voice-on` - Enable text-to-speech for current directory -- `/voice-off` - Disable text-to-speech for current directory +- `/voice-on` - Enable text-to-speech globally +- `/voice-off` - Disable text-to-speech globally + +#### Raycast Integration +For quick voice control, use the included Raycast scripts: +- **"Toggle Claude Voice"** - Toggle voice on/off from anywhere +- **"Stop Voice (TTS)"** - Immediately stop any playing speech + +To add to Raycast: Add the `raycast-scripts/` directory to your Raycast script directories. #### Selecting and Downloading High Quality System Voices @@ -46,8 +53,8 @@ For the best text-to-speech experience, download high-quality system voices: **Recommended**: Siri voices provide the most natural speech quality but require downloading additional voice data. -#### Voice Database -Voice settings are stored per-directory in `~/.claude/voice-db.json` and automatically created by the scripts. +#### Voice Settings +Voice is controlled by a global flag file at `~/.claude/voice-enabled`. When this file exists, Claude Code will speak all responses. ### Other Applications - **tmux**: Terminal multiplexer with custom configuration diff --git a/README_cn.md b/README_cn.md index 1e1a622..9329131 100644 --- a/README_cn.md +++ b/README_cn.md @@ -30,11 +30,18 @@ ### Claude Code 语音配置 -此配置包含一个基于目录的 Claude Code 语音系统,使用 macOS 文本转语音功能。 +此配置包含一个全局的 Claude Code 语音系统,使用 macOS 文本转语音功能。 #### 语音命令 -- `/voice-on` - 为当前目录启用文本转语音 -- `/voice-off` - 为当前目录禁用文本转语音 +- `/voice-on` - 全局启用文本转语音 +- `/voice-off` - 全局禁用文本转语音 + +#### Raycast 集成 +为了快速语音控制,使用包含的 Raycast 脚本: +- **"Toggle Claude Voice"** - 从任何地方切换语音开/关 +- **"Stop Voice (TTS)"** - 立即停止任何正在播放的语音 + +添加到 Raycast:将 `raycast-scripts/` 目录添加到您的 Raycast 脚本目录。 #### 选择和下载高质量系统语音 @@ -48,8 +55,8 @@ **推荐**: Siri 语音提供最自然的语音质量,但需要下载额外的语音数据。 -#### 语音数据库 -语音设置按目录存储在 `~/.claude/voice-db.json` 中,由脚本自动创建。 +#### 语音设置 +语音由全局标志文件 `~/.claude/voice-enabled` 控制。当此文件存在时,Claude Code 将朗读所有响应。 ### 其他应用程序 - **tmux**: 带有自定义配置的终端复用器 diff --git a/claude/scripts/voice-off.sh b/claude/scripts/voice-off.sh deleted file mode 100755 index a4dff19..0000000 --- a/claude/scripts/voice-off.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -current_dir=$(pwd) -voice_db="$HOME/.claude/voice-db.json" - -# Create voice database if it doesn't exist -if [ ! -f "$voice_db" ]; then - echo "{}" > "$voice_db" -fi - -jq --arg dir "$current_dir" '.[$dir] = false' "$voice_db" > /tmp/voice-db-temp.json && mv /tmp/voice-db-temp.json "$voice_db" -echo "Voice disabled for $current_dir" \ No newline at end of file diff --git a/claude/scripts/voice-on.sh b/claude/scripts/voice-on.sh deleted file mode 100755 index 2f4f82f..0000000 --- a/claude/scripts/voice-on.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -current_dir=$(pwd) -voice_db="$HOME/.claude/voice-db.json" - -# Create voice database if it doesn't exist -if [ ! -f "$voice_db" ]; then - echo "{}" > "$voice_db" -fi - -jq --arg dir "$current_dir" '.[$dir] = true' "$voice_db" > /tmp/voice-db-temp.json && mv /tmp/voice-db-temp.json "$voice_db" -echo "Voice enabled for $current_dir" \ No newline at end of file diff --git a/claude/settings.json b/claude/settings.json index 18bd41d..76fa96f 100644 --- a/claude/settings.json +++ b/claude/settings.json @@ -12,7 +12,7 @@ "hooks": [ { "type": "command", - "command": "current_dir=$(pwd); voice_db=\"$HOME/.claude/voice-db.json\"; if [ -f \"$voice_db\" ] && [ \"$(jq -r --arg dir \"$current_dir\" '.[$dir] // false' \"$voice_db\")\" = \"true\" ]; then transcript_path=$(cat | jq -r '.transcript_path'); nohup bash -c 'tail -1 \"'$transcript_path'\" | jq -r \".message.content[0].text // empty\" | say' >/dev/null 2>&1 & fi" + "command": "voice_flag=\"$HOME/.claude/voice-enabled\"; if [ -f \"$voice_flag\" ]; then transcript_path=$(cat | jq -r '.transcript_path'); pkill -f 'say' 2>/dev/null; nohup bash -c 'tail -1 \"'$transcript_path'\" | jq -r \".message.content[0].text // empty\" | say' >/dev/null 2>&1 & fi" } ] } diff --git a/raycast-scripts/claude-code-voice-toggle.sh b/raycast-scripts/claude-code-voice-toggle.sh new file mode 100755 index 0000000..52bade5 --- /dev/null +++ b/raycast-scripts/claude-code-voice-toggle.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Toggle Claude Voice +# @raycast.mode compact + +# Optional parameters: +# @raycast.icon 🔊 +# @raycast.description Toggle Claude Code voice on/off globally + +voice_flag="$HOME/.claude/voice-enabled" + +if [ -f "$voice_flag" ]; then + # Voice is currently on, turn it off + rm -f "$voice_flag" + pkill -f 'say' 2>/dev/null + echo "Claude Voice OFF" +else + # Voice is currently off, turn it on + touch "$voice_flag" + echo "Claude Voice ON" +fi \ No newline at end of file diff --git a/raycast-scripts/stop-voice-tts.sh b/raycast-scripts/stop-voice-tts.sh new file mode 100755 index 0000000..abcf449 --- /dev/null +++ b/raycast-scripts/stop-voice-tts.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Stop Voice (TTS) +# @raycast.mode compact + +# Optional parameters: +# @raycast.icon 🔇 +# @raycast.description Stop all text-to-speech playback + +# Kill all running say processes +pkill -f 'say' 2>/dev/null + +echo "All TTS stopped" \ No newline at end of file