agentvibes 2.0.9 → 2.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/.claude/commands/agent-vibes/bmad.md +203 -0
  2. package/.claude/github-star-reminder.txt +1 -0
  3. package/.claude/hooks/bmad-tts-injector.sh +333 -0
  4. package/.claude/hooks/bmad-voice-manager.sh +34 -0
  5. package/.claude/hooks/check-output-style.sh +2 -2
  6. package/.claude/hooks/github-star-reminder.sh +94 -0
  7. package/.claude/hooks/personality-manager.sh +2 -2
  8. package/.claude/hooks/piper-installer.sh +194 -0
  9. package/.claude/hooks/play-tts-elevenlabs.sh +30 -3
  10. package/.claude/hooks/play-tts-local-wrapper.sh +44 -0
  11. package/.claude/hooks/play-tts-piper.sh +10 -2
  12. package/.claude/hooks/play-tts-remote.sh +81 -0
  13. package/.claude/hooks/play-tts.sh +34 -0
  14. package/.claude/hooks/provider-commands.sh +30 -1
  15. package/.claude/hooks/voice-manager.sh +2 -2
  16. package/.claude/output-styles/agent-vibes.md +52 -36
  17. package/README.md +2 -2
  18. package/RELEASE_NOTES.md +412 -0
  19. package/agentvibes.org/.claude/commands/agent-vibes/add.md +21 -0
  20. package/agentvibes.org/.claude/commands/agent-vibes/agent-vibes.md +68 -0
  21. package/agentvibes.org/.claude/commands/agent-vibes/commands.json +53 -0
  22. package/agentvibes.org/.claude/commands/agent-vibes/get.md +9 -0
  23. package/agentvibes.org/.claude/commands/agent-vibes/list.md +13 -0
  24. package/agentvibes.org/.claude/commands/agent-vibes/personality.md +79 -0
  25. package/agentvibes.org/.claude/commands/agent-vibes/preview.md +16 -0
  26. package/agentvibes.org/.claude/commands/agent-vibes/provider.md +54 -0
  27. package/agentvibes.org/.claude/commands/agent-vibes/replay.md +19 -0
  28. package/agentvibes.org/.claude/commands/agent-vibes/sample.md +12 -0
  29. package/agentvibes.org/.claude/commands/agent-vibes/sentiment.md +52 -0
  30. package/agentvibes.org/.claude/commands/agent-vibes/set-language.md +47 -0
  31. package/agentvibes.org/.claude/commands/agent-vibes/set-pretext.md +65 -0
  32. package/agentvibes.org/.claude/commands/agent-vibes/switch.md +53 -0
  33. package/agentvibes.org/.claude/commands/agent-vibes/update.md +20 -0
  34. package/agentvibes.org/.claude/commands/agent-vibes/version.md +10 -0
  35. package/agentvibes.org/.claude/commands/agent-vibes/whoami.md +7 -0
  36. package/agentvibes.org/.claude/hooks/bmad-voice-manager.sh +278 -0
  37. package/agentvibes.org/.claude/hooks/language-manager.sh +190 -0
  38. package/agentvibes.org/.claude/hooks/personality-manager.sh +279 -0
  39. package/agentvibes.org/.claude/hooks/piper-download-voices.sh +133 -0
  40. package/agentvibes.org/.claude/hooks/piper-voice-manager.sh +227 -0
  41. package/agentvibes.org/.claude/hooks/play-tts-elevenlabs.sh +201 -0
  42. package/agentvibes.org/.claude/hooks/play-tts-piper.sh +175 -0
  43. package/agentvibes.org/.claude/hooks/play-tts.sh +138 -0
  44. package/agentvibes.org/.claude/hooks/provider-commands.sh +374 -0
  45. package/agentvibes.org/.claude/hooks/provider-manager.sh +196 -0
  46. package/agentvibes.org/.claude/hooks/sentiment-manager.sh +163 -0
  47. package/agentvibes.org/.claude/hooks/voice-manager.sh +349 -0
  48. package/agentvibes.org/.claude/hooks/voices-config.sh +33 -0
  49. package/agentvibes.org/.claude/journal/2025-10-07.html +373 -0
  50. package/agentvibes.org/.claude/journal/index.html +91 -0
  51. package/agentvibes.org/.claude/output-styles/agent-vibes.md +203 -0
  52. package/agentvibes.org/.claude/personalities/angry.md +16 -0
  53. package/agentvibes.org/.claude/personalities/annoying.md +16 -0
  54. package/agentvibes.org/.claude/personalities/crass.md +16 -0
  55. package/agentvibes.org/.claude/personalities/dramatic.md +16 -0
  56. package/agentvibes.org/.claude/personalities/dry-humor.md +52 -0
  57. package/agentvibes.org/.claude/personalities/flirty.md +22 -0
  58. package/agentvibes.org/.claude/personalities/funny.md +16 -0
  59. package/agentvibes.org/.claude/personalities/grandpa.md +34 -0
  60. package/agentvibes.org/.claude/personalities/millennial.md +16 -0
  61. package/agentvibes.org/.claude/personalities/moody.md +16 -0
  62. package/agentvibes.org/.claude/personalities/normal.md +18 -0
  63. package/agentvibes.org/.claude/personalities/pirate.md +16 -0
  64. package/agentvibes.org/.claude/personalities/poetic.md +16 -0
  65. package/agentvibes.org/.claude/personalities/professional.md +16 -0
  66. package/agentvibes.org/.claude/personalities/robot.md +16 -0
  67. package/agentvibes.org/.claude/personalities/sarcastic.md +40 -0
  68. package/agentvibes.org/.claude/personalities/sassy.md +16 -0
  69. package/agentvibes.org/.claude/personalities/surfer-dude.md +16 -0
  70. package/agentvibes.org/.claude/personalities/zen.md +16 -0
  71. package/agentvibes.org/.mcp-minimal.json +60 -0
  72. package/agentvibes.org/CHANGELOG.md +56 -0
  73. package/agentvibes.org/README.md +93 -0
  74. package/agentvibes.org/app/(auth)/layout.tsx +15 -0
  75. package/agentvibes.org/app/(auth)/reset-password/page.tsx +45 -0
  76. package/agentvibes.org/app/(auth)/signin/page.tsx +82 -0
  77. package/agentvibes.org/app/(auth)/signup/page.tsx +104 -0
  78. package/agentvibes.org/app/(default)/layout.tsx +31 -0
  79. package/agentvibes.org/app/(default)/page.tsx +20 -0
  80. package/agentvibes.org/app/api/hello/route.ts +3 -0
  81. package/agentvibes.org/app/css/additional-styles/theme.css +82 -0
  82. package/agentvibes.org/app/css/additional-styles/utility-patterns.css +55 -0
  83. package/agentvibes.org/app/css/style.css +100 -0
  84. package/agentvibes.org/app/layout.tsx +63 -0
  85. package/agentvibes.org/components/cta.tsx +58 -0
  86. package/agentvibes.org/components/features.tsx +256 -0
  87. package/agentvibes.org/components/hero-home.tsx +133 -0
  88. package/agentvibes.org/components/modal-video.tsx +137 -0
  89. package/agentvibes.org/components/page-illustration.tsx +55 -0
  90. package/agentvibes.org/components/spotlight.tsx +77 -0
  91. package/agentvibes.org/components/testimonials.tsx +282 -0
  92. package/agentvibes.org/components/ui/footer.tsx +82 -0
  93. package/agentvibes.org/components/ui/header.tsx +53 -0
  94. package/agentvibes.org/components/ui/logo.tsx +10 -0
  95. package/agentvibes.org/components/workflows.tsx +176 -0
  96. package/agentvibes.org/next.config.js +4 -0
  97. package/agentvibes.org/package-lock.json +1974 -0
  98. package/agentvibes.org/package.json +30 -0
  99. package/agentvibes.org/pnpm-lock.yaml +1141 -0
  100. package/agentvibes.org/postcss.config.js +5 -0
  101. package/agentvibes.org/public/audio/02-sarcastic.mp3 +0 -0
  102. package/agentvibes.org/public/audio/03-angry.mp3 +0 -0
  103. package/agentvibes.org/public/audio/04-grandpa.mp3 +0 -0
  104. package/agentvibes.org/public/audio/05-sarcastic-example2.mp3 +0 -0
  105. package/agentvibes.org/public/audio/french-rachel.mp3 +0 -0
  106. package/agentvibes.org/public/audio/spanish-antoni.mp3 +0 -0
  107. package/agentvibes.org/public/favicon.ico +0 -0
  108. package/agentvibes.org/public/fonts/nacelle-italic.woff2 +0 -0
  109. package/agentvibes.org/public/fonts/nacelle-regular.woff2 +0 -0
  110. package/agentvibes.org/public/fonts/nacelle-semibold.woff2 +0 -0
  111. package/agentvibes.org/public/fonts/nacelle-semibolditalic.woff2 +0 -0
  112. package/agentvibes.org/public/images/blurred-shape-gray.svg +1 -0
  113. package/agentvibes.org/public/images/blurred-shape.svg +1 -0
  114. package/agentvibes.org/public/images/client-logo-01.svg +1 -0
  115. package/agentvibes.org/public/images/client-logo-02.svg +1 -0
  116. package/agentvibes.org/public/images/client-logo-03.svg +1 -0
  117. package/agentvibes.org/public/images/client-logo-04.svg +1 -0
  118. package/agentvibes.org/public/images/client-logo-05.svg +1 -0
  119. package/agentvibes.org/public/images/client-logo-06.svg +1 -0
  120. package/agentvibes.org/public/images/client-logo-07.svg +1 -0
  121. package/agentvibes.org/public/images/client-logo-08.svg +1 -0
  122. package/agentvibes.org/public/images/client-logo-09.svg +1 -0
  123. package/agentvibes.org/public/images/features.png +0 -0
  124. package/agentvibes.org/public/images/footer-illustration.svg +1 -0
  125. package/agentvibes.org/public/images/hero-image-01.jpg +0 -0
  126. package/agentvibes.org/public/images/logo.svg +1 -0
  127. package/agentvibes.org/public/images/page-illustration.svg +1 -0
  128. package/agentvibes.org/public/images/secondary-illustration.svg +1 -0
  129. package/agentvibes.org/public/images/testimonial-01.jpg +0 -0
  130. package/agentvibes.org/public/images/testimonial-02.jpg +0 -0
  131. package/agentvibes.org/public/images/testimonial-03.jpg +0 -0
  132. package/agentvibes.org/public/images/testimonial-04.jpg +0 -0
  133. package/agentvibes.org/public/images/testimonial-05.jpg +0 -0
  134. package/agentvibes.org/public/images/testimonial-06.jpg +0 -0
  135. package/agentvibes.org/public/images/testimonial-07.jpg +0 -0
  136. package/agentvibes.org/public/images/testimonial-08.jpg +0 -0
  137. package/agentvibes.org/public/images/testimonial-09.jpg +0 -0
  138. package/agentvibes.org/public/images/workflow-01.png +0 -0
  139. package/agentvibes.org/public/images/workflow-02.png +0 -0
  140. package/agentvibes.org/public/images/workflow-03.png +0 -0
  141. package/agentvibes.org/public/videos/video.mp4 +0 -0
  142. package/agentvibes.org/tsconfig.json +28 -0
  143. package/agentvibes.org/utils/useMasonry.tsx +67 -0
  144. package/agentvibes.org/utils/useMousePosition.tsx +27 -0
  145. package/docs/REMOTE_TTS_SETUP.md +190 -0
  146. package/package.json +2 -2
  147. package/src/installer.js +193 -9
  148. package/test/helpers/test-helper.bash +4 -2
  149. package/test/unit/personality-manager.bats +16 -4
  150. package/test/unit/personality-voice-mapping.bats +15 -6
  151. package/test/unit/play-tts.bats +0 -9
  152. package/.claude/commands/agent-vibes-bmad.md +0 -132
@@ -0,0 +1,227 @@
1
+ #!/bin/bash
2
+ #
3
+ # @fileoverview Piper Voice Model Management
4
+ # @context Manages downloading, caching, and validating Piper ONNX voice models
5
+ # @architecture Voice model lifecycle management for Piper provider
6
+ # @dependencies curl, piper binary
7
+ # @entrypoints Sourced by play-tts-piper.sh and provider management commands
8
+ # @patterns HuggingFace model repository integration, file-based caching
9
+ # @related play-tts-piper.sh, provider-manager.sh, GitHub Issue #25
10
+ #
11
+
12
+ # Base URL for Piper voice models on HuggingFace
13
+ PIPER_VOICES_BASE_URL="https://huggingface.co/rhasspy/piper-voices/resolve/main"
14
+
15
+ # @function get_voice_storage_dir
16
+ # @intent Determine directory for storing Piper voice models
17
+ # @why Voice models are large (~25MB each) and should be shared globally across all projects
18
+ # @returns Echoes path to voice storage directory (~/.claude/piper-voices)
19
+ # @sideeffects Creates directory if it doesn't exist
20
+ # @architecture Supports custom path via PIPER_VOICES_DIR env var, defaults to global storage
21
+ get_voice_storage_dir() {
22
+ local voice_dir
23
+
24
+ # Check for custom path in environment or config file
25
+ if [[ -n "$PIPER_VOICES_DIR" ]]; then
26
+ voice_dir="$PIPER_VOICES_DIR"
27
+ else
28
+ # Check for config file (project-local first, then global)
29
+ local config_file
30
+ if [[ -n "$CLAUDE_PROJECT_DIR" ]] && [[ -f "$CLAUDE_PROJECT_DIR/.claude/piper-voices-dir.txt" ]]; then
31
+ config_file="$CLAUDE_PROJECT_DIR/.claude/piper-voices-dir.txt"
32
+ else
33
+ # Search up directory tree for .claude/
34
+ local current_dir="$PWD"
35
+ while [[ "$current_dir" != "/" ]]; do
36
+ if [[ -f "$current_dir/.claude/piper-voices-dir.txt" ]]; then
37
+ config_file="$current_dir/.claude/piper-voices-dir.txt"
38
+ break
39
+ fi
40
+ current_dir=$(dirname "$current_dir")
41
+ done
42
+
43
+ # Check global config
44
+ if [[ -z "$config_file" ]] && [[ -f "$HOME/.claude/piper-voices-dir.txt" ]]; then
45
+ config_file="$HOME/.claude/piper-voices-dir.txt"
46
+ fi
47
+ fi
48
+
49
+ if [[ -n "$config_file" ]]; then
50
+ voice_dir=$(cat "$config_file" | tr -d '[:space:]')
51
+ fi
52
+ fi
53
+
54
+ # Fallback to default global storage
55
+ if [[ -z "$voice_dir" ]]; then
56
+ voice_dir="$HOME/.claude/piper-voices"
57
+ fi
58
+
59
+ mkdir -p "$voice_dir"
60
+ echo "$voice_dir"
61
+ }
62
+
63
+ # @function verify_voice
64
+ # @intent Check if voice model files exist locally
65
+ # @why Avoid redundant downloads, detect missing models
66
+ # @param $1 {string} voice_name - Voice model name (e.g., en_US-lessac-medium)
67
+ # @returns None
68
+ # @exitcode 0=voice exists, 1=voice missing
69
+ # @sideeffects None
70
+ verify_voice() {
71
+ local voice_name="$1"
72
+ local voice_dir
73
+ voice_dir=$(get_voice_storage_dir)
74
+
75
+ local onnx_file="$voice_dir/${voice_name}.onnx"
76
+ local json_file="$voice_dir/${voice_name}.onnx.json"
77
+
78
+ [[ -f "$onnx_file" ]] && [[ -f "$json_file" ]]
79
+ }
80
+
81
+ # @function get_voice_path
82
+ # @intent Get absolute path to voice model ONNX file
83
+ # @why Piper binary requires full path to model file
84
+ # @param $1 {string} voice_name - Voice model name
85
+ # @returns Echoes path to .onnx file
86
+ # @exitcode 0=success, 1=voice not found
87
+ # @sideeffects None
88
+ get_voice_path() {
89
+ local voice_name="$1"
90
+ local voice_dir
91
+ voice_dir=$(get_voice_storage_dir)
92
+
93
+ local onnx_file="$voice_dir/${voice_name}.onnx"
94
+
95
+ if [[ ! -f "$onnx_file" ]]; then
96
+ echo "❌ Voice model not found: $voice_name" >&2
97
+ return 1
98
+ fi
99
+
100
+ echo "$onnx_file"
101
+ }
102
+
103
+ # @function parse_voice_components
104
+ # @intent Extract language, locale, speaker, quality from voice name
105
+ # @why HuggingFace uses directory structure: lang/locale/speaker/quality
106
+ # @param $1 {string} voice_name - Voice name (e.g., en_US-lessac-medium)
107
+ # @returns Sets global variables: LANG, LOCALE, SPEAKER, QUALITY
108
+ # @sideeffects Sets global variables
109
+ # AI NOTE: Voice name format is: lang_LOCALE-speaker-quality
110
+ parse_voice_components() {
111
+ local voice_name="$1"
112
+
113
+ # Extract components from voice name
114
+ # Format: en_US-lessac-medium
115
+ # lang_LOCALE-speaker-quality
116
+
117
+ local lang_locale="${voice_name%%-*}" # en_US
118
+ local speaker_quality="${voice_name#*-}" # lessac-medium
119
+
120
+ LANG="${lang_locale%%_*}" # en
121
+ LOCALE="${lang_locale#*_}" # US
122
+ SPEAKER="${speaker_quality%%-*}" # lessac
123
+ QUALITY="${speaker_quality#*-}" # medium
124
+ }
125
+
126
+ # @function download_voice
127
+ # @intent Download Piper voice model from HuggingFace
128
+ # @why Provide free offline TTS voices
129
+ # @param $1 {string} voice_name - Voice model name
130
+ # @param $2 {string} lang_code - Language code (optional, inferred from voice_name)
131
+ # @returns None
132
+ # @exitcode 0=success, 1=download failed
133
+ # @sideeffects Downloads .onnx and .onnx.json files
134
+ # @edgecases Handles network failures, validates file integrity
135
+ download_voice() {
136
+ local voice_name="$1"
137
+ local lang_code="${2:-}"
138
+
139
+ local voice_dir
140
+ voice_dir=$(get_voice_storage_dir)
141
+
142
+ # Check if already downloaded
143
+ if verify_voice "$voice_name"; then
144
+ echo "✅ Voice already downloaded: $voice_name"
145
+ return 0
146
+ fi
147
+
148
+ # Parse voice components
149
+ parse_voice_components "$voice_name"
150
+
151
+ # Construct download URLs
152
+ # Path format: {language}/{language}_{locale}/{speaker}/{quality}/{speaker}-{quality}.onnx
153
+ local model_path="${LANG}/${LANG}_${LOCALE}/${SPEAKER}/${QUALITY}/${voice_name}"
154
+ local onnx_url="${PIPER_VOICES_BASE_URL}/${model_path}.onnx"
155
+ local json_url="${PIPER_VOICES_BASE_URL}/${model_path}.onnx.json"
156
+
157
+ echo "📥 Downloading Piper voice: $voice_name"
158
+ echo " Source: HuggingFace (rhasspy/piper-voices)"
159
+ echo " Size: ~25MB"
160
+ echo ""
161
+
162
+ # Download ONNX model
163
+ echo " Downloading model file..."
164
+ if ! curl -L --progress-bar -o "$voice_dir/${voice_name}.onnx" "$onnx_url"; then
165
+ echo "❌ Failed to download voice model"
166
+ rm -f "$voice_dir/${voice_name}.onnx"
167
+ return 1
168
+ fi
169
+
170
+ # Download JSON config
171
+ echo " Downloading config file..."
172
+ if ! curl -L -s -o "$voice_dir/${voice_name}.onnx.json" "$json_url"; then
173
+ echo "❌ Failed to download voice config"
174
+ rm -f "$voice_dir/${voice_name}.onnx" "$voice_dir/${voice_name}.onnx.json"
175
+ return 1
176
+ fi
177
+
178
+ # Verify file integrity (basic check - file size > 0)
179
+ if [[ ! -s "$voice_dir/${voice_name}.onnx" ]]; then
180
+ echo "❌ Downloaded file is empty or corrupt"
181
+ rm -f "$voice_dir/${voice_name}.onnx" "$voice_dir/${voice_name}.onnx.json"
182
+ return 1
183
+ fi
184
+
185
+ echo "✅ Voice downloaded successfully: $voice_name"
186
+ echo " Location: $voice_dir/${voice_name}.onnx"
187
+ }
188
+
189
+ # @function list_downloaded_voices
190
+ # @intent Show all locally cached voice models
191
+ # @why Help users see what voices they have available
192
+ # @returns Echoes voice names (one per line)
193
+ # @exitcode 0=success
194
+ # @sideeffects None
195
+ list_downloaded_voices() {
196
+ local voice_dir
197
+ voice_dir=$(get_voice_storage_dir)
198
+
199
+ echo "📦 Downloaded Piper Voices:"
200
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
201
+
202
+ local count=0
203
+ shopt -s nullglob
204
+ for onnx_file in "$voice_dir"/*.onnx; do
205
+ if [[ -f "$onnx_file" ]]; then
206
+ local voice_name
207
+ voice_name=$(basename "$onnx_file" .onnx)
208
+ local file_size
209
+ file_size=$(du -h "$onnx_file" | cut -f1)
210
+ echo " • $voice_name ($file_size)"
211
+ ((count++))
212
+ fi
213
+ done
214
+ shopt -u nullglob
215
+
216
+ if [[ $count -eq 0 ]]; then
217
+ echo " (No voices downloaded yet)"
218
+ fi
219
+
220
+ echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
221
+ echo "Total: $count voices"
222
+ }
223
+
224
+ # AI NOTE: This file manages the lifecycle of Piper voice models
225
+ # Voice models are ONNX files (~20-30MB each) downloaded from HuggingFace
226
+ # Files are cached locally to avoid repeated downloads
227
+ # Project-local storage preferred over global for isolation
@@ -0,0 +1,201 @@
1
+ #!/bin/bash
2
+ #
3
+ # @fileoverview ElevenLabs TTS Provider Implementation
4
+ # @context Provider-specific implementation for ElevenLabs API integration
5
+ # @architecture Part of multi-provider TTS system - implements provider interface
6
+ # @dependencies Requires ELEVENLABS_API_KEY, curl, ffmpeg, paplay/aplay/mpg123, jq
7
+ # @entrypoints Called by play-tts.sh router with ($1=text, $2=voice_name)
8
+ # @patterns Follows provider contract: accept text/voice, output audio file path
9
+ # @related play-tts.sh, provider-manager.sh, GitHub Issue #25
10
+ #
11
+
12
+ # Fix locale warnings
13
+ export LC_ALL=C
14
+
15
+ TEXT="$1"
16
+ VOICE_OVERRIDE="$2" # Optional: voice name or direct voice ID
17
+ API_KEY="${ELEVENLABS_API_KEY}"
18
+
19
+ # Check for project-local pretext configuration
20
+ CONFIG_DIR="${CLAUDE_PROJECT_DIR:-.}/.claude/config"
21
+ CONFIG_FILE="$CONFIG_DIR/agentvibes.json"
22
+
23
+ if [[ -f "$CONFIG_FILE" ]] && command -v jq &> /dev/null; then
24
+ PRETEXT=$(jq -r '.pretext // empty' "$CONFIG_FILE" 2>/dev/null)
25
+ if [[ -n "$PRETEXT" ]]; then
26
+ TEXT="$PRETEXT: $TEXT"
27
+ fi
28
+ fi
29
+
30
+ # Limit text length to prevent API issues (max 500 chars for safety)
31
+ if [ ${#TEXT} -gt 500 ]; then
32
+ TEXT="${TEXT:0:497}..."
33
+ echo "⚠️ Text truncated to 500 characters for API safety"
34
+ fi
35
+
36
+ # Source the single voice configuration file
37
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38
+ source "$SCRIPT_DIR/voices-config.sh"
39
+ source "$SCRIPT_DIR/language-manager.sh"
40
+
41
+ # @function determine_voice_and_language
42
+ # @intent Resolve voice name/ID and language for multilingual support
43
+ # @why Supports both voice names and direct IDs, plus language-specific voices
44
+ # @param $VOICE_OVERRIDE {string} Voice name or ID (optional)
45
+ # @returns Sets $VOICE_ID and $LANGUAGE_CODE global variables
46
+ # @sideeffects None
47
+ # @edgecases Handles unknown voices, falls back to default
48
+ VOICE_ID=""
49
+ LANGUAGE_CODE="en" # Default to English
50
+
51
+ # Get current language setting
52
+ CURRENT_LANGUAGE=$(get_current_language)
53
+
54
+ # Get language code for API
55
+ LANGUAGE_CODE=$(get_language_code_for_name "$CURRENT_LANGUAGE")
56
+ [[ -z "$LANGUAGE_CODE" ]] && LANGUAGE_CODE="en"
57
+
58
+ if [[ -n "$VOICE_OVERRIDE" ]]; then
59
+ # Check if override is a voice name (lookup in mapping)
60
+ if [[ -n "${VOICES[$VOICE_OVERRIDE]}" ]]; then
61
+ VOICE_ID="${VOICES[$VOICE_OVERRIDE]}"
62
+ echo "🎤 Using voice: $VOICE_OVERRIDE (session-specific)"
63
+ # Check if override looks like a voice ID (alphanumeric string ~20 chars)
64
+ elif [[ "$VOICE_OVERRIDE" =~ ^[a-zA-Z0-9]{15,30}$ ]]; then
65
+ VOICE_ID="$VOICE_OVERRIDE"
66
+ echo "🎤 Using custom voice ID (session-specific)"
67
+ else
68
+ echo "⚠️ Unknown voice '$VOICE_OVERRIDE', trying language-specific voice"
69
+ fi
70
+ fi
71
+
72
+ # If no override or invalid override, use language-specific voice
73
+ if [[ -z "$VOICE_ID" ]]; then
74
+ # Try to get voice for current language
75
+ LANG_VOICE=$(get_voice_for_language "$CURRENT_LANGUAGE" "elevenlabs" 2>/dev/null)
76
+
77
+ if [[ -n "$LANG_VOICE" ]] && [[ -n "${VOICES[$LANG_VOICE]}" ]]; then
78
+ VOICE_ID="${VOICES[$LANG_VOICE]}"
79
+ echo "🌍 Using $CURRENT_LANGUAGE voice: $LANG_VOICE"
80
+ else
81
+ # Fall back to voice manager
82
+ VOICE_MANAGER_SCRIPT="$(dirname "$0")/voice-manager.sh"
83
+ if [[ -f "$VOICE_MANAGER_SCRIPT" ]]; then
84
+ VOICE_NAME=$("$VOICE_MANAGER_SCRIPT" get)
85
+ VOICE_ID="${VOICES[$VOICE_NAME]}"
86
+ fi
87
+
88
+ # Final fallback to default
89
+ if [[ -z "$VOICE_ID" ]]; then
90
+ echo "⚠️ No voice configured, using default"
91
+ VOICE_ID="${VOICES[Aria]}"
92
+ fi
93
+ fi
94
+ fi
95
+
96
+ # @function validate_inputs
97
+ # @intent Check required parameters and API key
98
+ # @why Fail fast with clear errors if inputs missing
99
+ # @exitcode 1=missing text, 2=missing API key
100
+ if [ -z "$TEXT" ]; then
101
+ echo "Usage: $0 \"text to speak\" [voice_name_or_id]"
102
+ exit 1
103
+ fi
104
+
105
+ if [ -z "$API_KEY" ]; then
106
+ echo "Error: ELEVENLABS_API_KEY not set"
107
+ echo "Set your API key: export ELEVENLABS_API_KEY=your_key_here"
108
+ exit 2
109
+ fi
110
+
111
+ # @function determine_audio_directory
112
+ # @intent Find appropriate directory for audio file storage
113
+ # @why Supports project-local and global storage
114
+ # @returns Sets $AUDIO_DIR global variable
115
+ # @sideeffects None
116
+ # @edgecases Handles missing directories, creates if needed
117
+ # AI NOTE: Check project dir first, then search up tree, finally fall back to global
118
+ if [[ -n "$CLAUDE_PROJECT_DIR" ]]; then
119
+ AUDIO_DIR="$CLAUDE_PROJECT_DIR/.claude/audio"
120
+ else
121
+ # Fallback: try to find .claude directory in current path
122
+ CURRENT_DIR="$PWD"
123
+ while [[ "$CURRENT_DIR" != "/" ]]; do
124
+ if [[ -d "$CURRENT_DIR/.claude" ]]; then
125
+ AUDIO_DIR="$CURRENT_DIR/.claude/audio"
126
+ break
127
+ fi
128
+ CURRENT_DIR=$(dirname "$CURRENT_DIR")
129
+ done
130
+ # Final fallback to global if no project .claude found
131
+ if [[ -z "$AUDIO_DIR" ]]; then
132
+ AUDIO_DIR="$HOME/.claude/audio"
133
+ fi
134
+ fi
135
+
136
+ mkdir -p "$AUDIO_DIR"
137
+ TEMP_FILE="$AUDIO_DIR/tts-$(date +%s).mp3"
138
+
139
+ # @function synthesize_with_elevenlabs
140
+ # @intent Call ElevenLabs API to generate speech
141
+ # @why Encapsulates API call with error handling
142
+ # @param Uses globals: $TEXT, $VOICE_ID, $API_KEY
143
+ # @returns Creates audio file at $TEMP_FILE
144
+ # @exitcode 0=success, 3=API error
145
+ # @sideeffects Creates MP3 file in audio directory
146
+ # @edgecases Handles network failures, API errors, rate limiting
147
+ # Choose model based on language
148
+ if [[ "$LANGUAGE_CODE" == "en" ]]; then
149
+ MODEL_ID="eleven_monolingual_v1"
150
+ else
151
+ MODEL_ID="eleven_multilingual_v2"
152
+ fi
153
+
154
+ curl -s -X POST "https://api.elevenlabs.io/v1/text-to-speech/${VOICE_ID}" \
155
+ -H "xi-api-key: ${API_KEY}" \
156
+ -H "Content-Type: application/json" \
157
+ -d "{\"text\":\"${TEXT}\",\"model_id\":\"${MODEL_ID}\",\"language_code\":\"${LANGUAGE_CODE}\",\"voice_settings\":{\"stability\":0.5,\"similarity_boost\":0.75}}" \
158
+ -o "${TEMP_FILE}"
159
+
160
+ # @function add_silence_padding
161
+ # @intent Add silence to beginning of audio to prevent WSL static
162
+ # @why WSL audio subsystem cuts off first ~200ms, causing static/clipping
163
+ # @param Uses global: $TEMP_FILE
164
+ # @returns Updates $TEMP_FILE to padded version
165
+ # @sideeffects Modifies audio file, removes original
166
+ # @edgecases Gracefully falls back to unpadded if ffmpeg unavailable
167
+ # Add silence padding to prevent WSL audio static
168
+ if [ -f "${TEMP_FILE}" ]; then
169
+ # Check if ffmpeg is available for adding padding
170
+ if command -v ffmpeg &> /dev/null; then
171
+ PADDED_FILE="$AUDIO_DIR/tts-padded-$(date +%s).mp3"
172
+ # Add 200ms of silence at the beginning to prevent static
173
+ ffmpeg -f lavfi -i anullsrc=r=44100:cl=stereo:d=0.2 -i "${TEMP_FILE}" \
174
+ -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1[out]" \
175
+ -map "[out]" -y "${PADDED_FILE}" 2>/dev/null
176
+
177
+ if [ -f "${PADDED_FILE}" ]; then
178
+ # Use padded file and clean up original
179
+ rm -f "${TEMP_FILE}"
180
+ TEMP_FILE="${PADDED_FILE}"
181
+ fi
182
+ # If padding failed, just use original file
183
+ fi
184
+
185
+ # @function play_audio
186
+ # @intent Play generated audio file using available player
187
+ # @why Support multiple audio players (paplay, aplay, mpg123)
188
+ # @param Uses global: $TEMP_FILE
189
+ # @sideeffects Plays audio in background
190
+ # @edgecases Falls through players until one works
191
+ # Play audio (WSL/Linux) in background to avoid blocking
192
+ (paplay "${TEMP_FILE}" 2>/dev/null || aplay "${TEMP_FILE}" 2>/dev/null || mpg123 "${TEMP_FILE}" 2>/dev/null) &
193
+
194
+ # Keep temp files for later review - cleaned up weekly by cron
195
+ echo "🎵 Saved to: ${TEMP_FILE}"
196
+ echo "🎤 Voice used: ${VOICE_NAME} (${VOICE_ID})"
197
+ else
198
+ echo "❌ Failed to generate audio - API may be unavailable"
199
+ echo "Check your API key and network connection"
200
+ exit 3
201
+ fi
@@ -0,0 +1,175 @@
1
+ #!/bin/bash
2
+ #
3
+ # @fileoverview Piper TTS Provider Implementation
4
+ # @context Free, offline neural TTS for WSL/Linux
5
+ # @architecture Implements provider contract for Piper binary
6
+ # @dependencies piper (pipx), piper-voice-manager.sh, mpv/aplay
7
+ # @entrypoints Called by play-tts.sh router
8
+ # @patterns Provider contract: text/voice → audio file path
9
+ # @related play-tts.sh, piper-voice-manager.sh, GitHub Issue #25
10
+ #
11
+
12
+ # Fix locale warnings
13
+ export LC_ALL=C
14
+
15
+ TEXT="$1"
16
+ VOICE_OVERRIDE="$2" # Optional: voice model name
17
+
18
+ # Source voice manager and language manager
19
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20
+ source "$SCRIPT_DIR/piper-voice-manager.sh"
21
+ source "$SCRIPT_DIR/language-manager.sh"
22
+
23
+ # Default voice for Piper
24
+ DEFAULT_VOICE="en_US-lessac-medium"
25
+
26
+ # @function determine_voice_model
27
+ # @intent Resolve voice name to Piper model name with language support
28
+ # @why Support voice override, language-specific voices, and default fallback
29
+ # @param Uses global: $VOICE_OVERRIDE
30
+ # @returns Sets $VOICE_MODEL global variable
31
+ # @sideeffects None
32
+ VOICE_MODEL=""
33
+
34
+ # Get current language setting
35
+ CURRENT_LANGUAGE=$(get_current_language)
36
+
37
+ if [[ -n "$VOICE_OVERRIDE" ]]; then
38
+ # Use override if provided
39
+ VOICE_MODEL="$VOICE_OVERRIDE"
40
+ echo "🎤 Using voice: $VOICE_OVERRIDE (session-specific)"
41
+ else
42
+ # Try to get language-specific voice
43
+ LANG_VOICE=$(get_voice_for_language "$CURRENT_LANGUAGE" "piper" 2>/dev/null)
44
+
45
+ if [[ -n "$LANG_VOICE" ]]; then
46
+ VOICE_MODEL="$LANG_VOICE"
47
+ echo "🌍 Using $CURRENT_LANGUAGE voice: $LANG_VOICE (Piper)"
48
+ else
49
+ # Use default voice
50
+ VOICE_MODEL="$DEFAULT_VOICE"
51
+ fi
52
+ fi
53
+
54
+ # @function validate_inputs
55
+ # @intent Check required parameters
56
+ # @why Fail fast with clear errors if inputs missing
57
+ # @exitcode 1=missing text, 2=missing piper binary
58
+ if [[ -z "$TEXT" ]]; then
59
+ echo "Usage: $0 \"text to speak\" [voice_model_name]"
60
+ exit 1
61
+ fi
62
+
63
+ # Check if Piper is installed
64
+ if ! command -v piper &> /dev/null; then
65
+ echo "❌ Error: Piper TTS not installed"
66
+ echo "Install with: pipx install piper-tts"
67
+ echo "Or run: .claude/hooks/piper-installer.sh"
68
+ exit 2
69
+ fi
70
+
71
+ # @function ensure_voice_downloaded
72
+ # @intent Download voice model if not cached
73
+ # @why Provide seamless experience with automatic downloads
74
+ # @param Uses global: $VOICE_MODEL
75
+ # @sideeffects Downloads voice model files
76
+ # @edgecases Prompts user for consent before downloading
77
+ if ! verify_voice "$VOICE_MODEL"; then
78
+ echo "📥 Voice model not found: $VOICE_MODEL"
79
+ echo " File size: ~25MB"
80
+ echo " Preview: https://huggingface.co/rhasspy/piper-voices"
81
+ echo ""
82
+ read -p " Download this voice model? [y/N]: " -n 1 -r
83
+ echo
84
+
85
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
86
+ if ! download_voice "$VOICE_MODEL"; then
87
+ echo "❌ Failed to download voice model"
88
+ echo "Fix: Download manually or choose different voice"
89
+ exit 3
90
+ fi
91
+ else
92
+ echo "❌ Voice download cancelled"
93
+ exit 3
94
+ fi
95
+ fi
96
+
97
+ # Get voice model path
98
+ VOICE_PATH=$(get_voice_path "$VOICE_MODEL")
99
+ if [[ $? -ne 0 ]]; then
100
+ echo "❌ Voice model path not found: $VOICE_MODEL"
101
+ exit 3
102
+ fi
103
+
104
+ # @function determine_audio_directory
105
+ # @intent Find appropriate directory for audio file storage
106
+ # @why Supports project-local and global storage
107
+ # @returns Sets $AUDIO_DIR global variable
108
+ if [[ -n "$CLAUDE_PROJECT_DIR" ]]; then
109
+ AUDIO_DIR="$CLAUDE_PROJECT_DIR/.claude/audio"
110
+ else
111
+ # Fallback: try to find .claude directory in current path
112
+ CURRENT_DIR="$PWD"
113
+ while [[ "$CURRENT_DIR" != "/" ]]; do
114
+ if [[ -d "$CURRENT_DIR/.claude" ]]; then
115
+ AUDIO_DIR="$CURRENT_DIR/.claude/audio"
116
+ break
117
+ fi
118
+ CURRENT_DIR=$(dirname "$CURRENT_DIR")
119
+ done
120
+ # Final fallback to global if no project .claude found
121
+ if [[ -z "$AUDIO_DIR" ]]; then
122
+ AUDIO_DIR="$HOME/.claude/audio"
123
+ fi
124
+ fi
125
+
126
+ mkdir -p "$AUDIO_DIR"
127
+ TEMP_FILE="$AUDIO_DIR/tts-$(date +%s).wav"
128
+
129
+ # @function synthesize_with_piper
130
+ # @intent Generate speech using Piper TTS
131
+ # @why Provides free, offline TTS alternative
132
+ # @param Uses globals: $TEXT, $VOICE_PATH
133
+ # @returns Creates WAV file at $TEMP_FILE
134
+ # @exitcode 0=success, 4=synthesis error
135
+ # @sideeffects Creates audio file
136
+ # @edgecases Handles piper errors, invalid models
137
+ echo "$TEXT" | piper --model "$VOICE_PATH" --output_file "$TEMP_FILE" 2>/dev/null
138
+
139
+ if [[ ! -f "$TEMP_FILE" ]] || [[ ! -s "$TEMP_FILE" ]]; then
140
+ echo "❌ Failed to synthesize speech with Piper"
141
+ echo "Voice model: $VOICE_MODEL"
142
+ echo "Check that voice model is valid"
143
+ exit 4
144
+ fi
145
+
146
+ # @function add_silence_padding
147
+ # @intent Add silence to prevent WSL audio static
148
+ # @why WSL audio subsystem cuts off first ~200ms
149
+ # @param Uses global: $TEMP_FILE
150
+ # @returns Updates $TEMP_FILE to padded version
151
+ # @sideeffects Modifies audio file
152
+ # AI NOTE: Use ffmpeg if available, otherwise skip padding (degraded experience)
153
+ if command -v ffmpeg &> /dev/null; then
154
+ PADDED_FILE="$AUDIO_DIR/tts-padded-$(date +%s).wav"
155
+ # Add 200ms of silence at the beginning
156
+ ffmpeg -f lavfi -i anullsrc=r=44100:cl=stereo:d=0.2 -i "$TEMP_FILE" \
157
+ -filter_complex "[0:a][1:a]concat=n=2:v=0:a=1[out]" \
158
+ -map "[out]" -y "$PADDED_FILE" 2>/dev/null
159
+
160
+ if [[ -f "$PADDED_FILE" ]]; then
161
+ rm -f "$TEMP_FILE"
162
+ TEMP_FILE="$PADDED_FILE"
163
+ fi
164
+ fi
165
+
166
+ # @function play_audio
167
+ # @intent Play generated audio using available player
168
+ # @why Support multiple audio players
169
+ # @param Uses global: $TEMP_FILE
170
+ # @sideeffects Plays audio in background
171
+ # Play audio (WSL/Linux) in background
172
+ (mpv "$TEMP_FILE" 2>/dev/null || aplay "$TEMP_FILE" 2>/dev/null || paplay "$TEMP_FILE" 2>/dev/null) &
173
+
174
+ echo "🎵 Saved to: $TEMP_FILE"
175
+ echo "🎤 Voice used: $VOICE_MODEL (Piper TTS)"