agentvibes 5.2.0 → 5.2.1

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 (49) hide show
  1. package/.claude/config/audio-effects.cfg +1 -1
  2. package/.claude/hooks/audio-cache-utils.sh +246 -246
  3. package/.claude/hooks/background-music-manager.sh +404 -404
  4. package/.claude/hooks/bmad-speak-enhanced.sh +165 -165
  5. package/.claude/hooks/bmad-speak.sh +290 -290
  6. package/.claude/hooks/bmad-tts-injector.sh +568 -568
  7. package/.claude/hooks/bmad-voice-manager.sh +928 -928
  8. package/.claude/hooks/clawdbot-receiver-SECURE.sh +129 -129
  9. package/.claude/hooks/clawdbot-receiver.sh +107 -107
  10. package/.claude/hooks/clean-audio-cache.sh +22 -22
  11. package/.claude/hooks/cleanup-cache.sh +106 -106
  12. package/.claude/hooks/configure-rdp-mode.sh +137 -137
  13. package/.claude/hooks/download-extra-voices.sh +244 -244
  14. package/.claude/hooks/effects-manager.sh +268 -268
  15. package/.claude/hooks/github-star-reminder.sh +154 -154
  16. package/.claude/hooks/language-manager.sh +362 -362
  17. package/.claude/hooks/learn-manager.sh +492 -492
  18. package/.claude/hooks/macos-voice-manager.sh +205 -205
  19. package/.claude/hooks/migrate-background-music.sh +125 -125
  20. package/.claude/hooks/migrate-to-agentvibes.sh +161 -161
  21. package/.claude/hooks/optimize-background-music.sh +87 -87
  22. package/.claude/hooks/path-resolver.sh +60 -60
  23. package/.claude/hooks/personality-manager.sh +448 -448
  24. package/.claude/hooks/piper-installer.sh +292 -292
  25. package/.claude/hooks/piper-multispeaker-registry.sh +171 -171
  26. package/.claude/hooks/play-tts-enhanced.sh +105 -105
  27. package/.claude/hooks/play-tts-termux-ssh.sh +169 -169
  28. package/.claude/hooks/play-tts.sh +14 -5
  29. package/.claude/hooks/prepare-release.sh +54 -54
  30. package/.claude/hooks/provider-commands.sh +617 -617
  31. package/.claude/hooks/provider-manager.sh +399 -399
  32. package/.claude/hooks/replay-target-audio.sh +95 -95
  33. package/.claude/hooks/sentiment-manager.sh +201 -201
  34. package/.claude/hooks/speed-manager.sh +291 -291
  35. package/.claude/hooks/stop-tts.sh +84 -84
  36. package/.claude/hooks/termux-installer.sh +261 -261
  37. package/.claude/hooks/translate-manager.sh +341 -341
  38. package/.claude/hooks/tts-queue-worker.sh +145 -145
  39. package/.claude/hooks/tts-queue.sh +165 -165
  40. package/.claude/hooks/voice-manager.sh +552 -548
  41. package/.claude/hooks-windows/play-tts.ps1 +2 -2
  42. package/README.md +11 -2
  43. package/RELEASE_NOTES.md +38 -0
  44. package/bin/mcp-server.sh +206 -206
  45. package/mcp-server/server.py +35 -6
  46. package/package.json +1 -1
  47. package/src/console/tabs/setup-tab.js +59 -23
  48. package/src/installer.js +79 -213
  49. package/src/services/llm-provider-service.js +126 -75
@@ -1,362 +1,362 @@
1
- #!/usr/bin/env bash
2
- #
3
- # File: .claude/hooks/language-manager.sh
4
- #
5
- # AgentVibes - Finally, your AI Agents can Talk Back! Text-to-Speech WITH personality for AI Assistants!
6
- # Website: https://agentvibes.org
7
- # Repository: https://github.com/paulpreibisch/AgentVibes
8
- #
9
- # Co-created by Paul Preibisch with Claude AI
10
- # Copyright (c) 2025 Paul Preibisch
11
- #
12
- # Licensed under the Apache License, Version 2.0 (the "License");
13
- # you may not use this file except in compliance with the License.
14
- # You may obtain a copy of the License at
15
- #
16
- # http://www.apache.org/licenses/LICENSE-2.0
17
- #
18
- # Unless required by applicable law or agreed to in writing, software
19
- # distributed under the License is distributed on an "AS IS" BASIS,
20
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- # See the License for the specific language governing permissions and
22
- # limitations under the License.
23
- #
24
- # DISCLAIMER: This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
- # express or implied. Use at your own risk. See the Apache License for details.
26
- #
27
- # ---
28
- #
29
- # @fileoverview Language Manager - Manages multilingual TTS with 30+ language support
30
- # @context Enables TTS in multiple languages with provider-specific voice recommendations (Piper native voices)
31
- # @architecture Dual-map system: PIPER_VOICES for provider-aware voice selection
32
- # @dependencies provider-manager.sh for active provider detection, .claude/tts-language.txt for state
33
- # @entrypoints Called by /agent-vibes:language commands, play-tts-*.sh for voice resolution
34
- # @patterns Provider abstraction, language-to-voice mapping, backward compatibility with legacy LANGUAGE_VOICES
35
- # @related play-tts-piper.sh, provider-manager.sh, learn-manager.sh
36
-
37
- # Determine target .claude directory based on context
38
- # Priority:
39
- # 1. CLAUDE_PROJECT_DIR env var (set by MCP for project-specific settings)
40
- # 2. Script location (for direct slash command usage)
41
- # 3. Global ~/.claude (fallback)
42
-
43
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44
-
45
- if [[ -n "${CLAUDE_PROJECT_DIR:-}" ]] && [[ -d "${CLAUDE_PROJECT_DIR:-}/.claude" ]]; then
46
- # MCP context: Use the project directory where MCP was invoked
47
- CLAUDE_DIR="$CLAUDE_PROJECT_DIR/.claude"
48
- else
49
- # Direct usage context: Use script location
50
- CLAUDE_DIR="$(cd "$SCRIPT_DIR/.." 2>/dev/null && pwd)"
51
-
52
- # If script is in global ~/.claude, use that
53
- if [[ "$CLAUDE_DIR" == "$HOME/.claude" ]]; then
54
- CLAUDE_DIR="$HOME/.claude"
55
- elif [[ ! -d "$CLAUDE_DIR" ]]; then
56
- # Fallback to global if directory doesn't exist
57
- CLAUDE_DIR="$HOME/.claude"
58
- fi
59
- fi
60
-
61
- LANGUAGE_FILE="$CLAUDE_DIR/tts-language.txt"
62
- mkdir -p "$CLAUDE_DIR"
63
-
64
- # Source provider manager to detect active provider
65
- source "$SCRIPT_DIR/provider-manager.sh" 2>/dev/null || true
66
-
67
- # =============================================================================
68
- # BASH 3.2 COMPATIBILITY: Function-based lookups instead of associative arrays
69
- # macOS ships with Bash 3.2 which doesn't support declare -A (added in Bash 4.0)
70
- # =============================================================================
71
-
72
-
73
- # Get Piper voice for a language
74
- _get_piper_voice() {
75
- local lang="$1"
76
- case "$lang" in
77
- spanish) echo "es_ES-davefx-medium" ;;
78
- french) echo "fr_FR-siwis-medium" ;;
79
- german) echo "de_DE-thorsten-medium" ;;
80
- italian) echo "it_IT-riccardo-x_low" ;;
81
- portuguese) echo "pt_BR-faber-medium" ;;
82
- chinese) echo "zh_CN-huayan-medium" ;;
83
- japanese) echo "ja_JP-hikari-medium" ;;
84
- korean) echo "ko_KR-eunyoung-medium" ;;
85
- russian) echo "ru_RU-dmitri-medium" ;;
86
- polish) echo "pl_PL-darkman-medium" ;;
87
- dutch) echo "nl_NL-rdh-medium" ;;
88
- turkish) echo "tr_TR-dfki-medium" ;;
89
- arabic) echo "ar_JO-kareem-medium" ;;
90
- hindi) echo "hi_IN-amitabh-medium" ;;
91
- swedish) echo "sv_SE-nst-medium" ;;
92
- danish) echo "da_DK-talesyntese-medium" ;;
93
- norwegian) echo "no_NO-talesyntese-medium" ;;
94
- finnish) echo "fi_FI-harri-medium" ;;
95
- czech) echo "cs_CZ-jirka-medium" ;;
96
- romanian) echo "ro_RO-mihai-medium" ;;
97
- ukrainian) echo "uk_UA-lada-x_low" ;;
98
- greek) echo "el_GR-rapunzelina-low" ;;
99
- bulgarian) echo "bg_BG-valentin-medium" ;;
100
- croatian) echo "hr_HR-gorana-medium" ;;
101
- slovak) echo "sk_SK-lili-medium" ;;
102
- *) echo "" ;;
103
- esac
104
- }
105
-
106
- # Get default (Piper) voice for a language - backward compatibility
107
- _get_language_voice() {
108
- _get_piper_voice "$1"
109
- }
110
-
111
- # Check if language is supported
112
- _is_language_supported() {
113
- local lang="$1"
114
- local voice
115
- voice=$(_get_piper_voice "$lang")
116
- [[ -n "$voice" ]]
117
- }
118
-
119
- # Supported languages list
120
- SUPPORTED_LANGUAGES="spanish, french, german, italian, portuguese, chinese, japanese, korean, polish, dutch, turkish, russian, arabic, hindi, swedish, danish, norwegian, finnish, czech, romanian, ukrainian, greek, bulgarian, croatian, slovak"
121
-
122
- # Function to set language
123
- set_language() {
124
- local lang="$1"
125
-
126
- # Convert to lowercase
127
- lang=$(echo "$lang" | tr '[:upper:]' '[:lower:]')
128
-
129
- # Handle reset/english
130
- if [[ "$lang" == "reset" ]] || [[ "$lang" == "english" ]] || [[ "$lang" == "en" ]]; then
131
- if [[ -f "$LANGUAGE_FILE" ]]; then
132
- rm "$LANGUAGE_FILE"
133
- echo "✓ Language reset to English (default)"
134
- else
135
- echo "Already using English (default)"
136
- fi
137
- return 0
138
- fi
139
-
140
- # Check if language is supported (Bash 3.2 compatible)
141
- if ! _is_language_supported "$lang"; then
142
- echo "❌ Language '$lang' not supported"
143
- echo ""
144
- echo "Supported languages:"
145
- echo "$SUPPORTED_LANGUAGES"
146
- return 1
147
- fi
148
-
149
- # Save language
150
- echo "$lang" > "$LANGUAGE_FILE"
151
-
152
- # Detect active provider and get recommended voice
153
- local provider=""
154
- if [[ -f "$CLAUDE_DIR/tts-provider.txt" ]]; then
155
- provider=$(cat "$CLAUDE_DIR/tts-provider.txt")
156
- elif [[ -f "$HOME/.claude/tts-provider.txt" ]]; then
157
- provider=$(cat "$HOME/.claude/tts-provider.txt")
158
- else
159
- provider="piper"
160
- fi
161
-
162
- local recommended_voice
163
- recommended_voice=$(get_voice_for_language "$lang" "$provider")
164
-
165
- # Fallback to default mapping if provider-aware function returns empty
166
- if [[ -z "$recommended_voice" ]]; then
167
- recommended_voice=$(_get_language_voice "$lang")
168
- fi
169
-
170
- echo "✓ Language set to: $lang"
171
- echo "📢 Recommended voice for $provider TTS: $recommended_voice"
172
- echo ""
173
- echo "TTS will now speak in $lang."
174
- echo "Switch voice with: /agent-vibes:switch \"$recommended_voice\""
175
- }
176
-
177
- # Function to get current language
178
- get_language() {
179
- if [[ -f "$LANGUAGE_FILE" ]]; then
180
- local lang=$(cat "$LANGUAGE_FILE")
181
-
182
- # Detect active provider
183
- local provider=""
184
- if [[ -f "$CLAUDE_DIR/tts-provider.txt" ]]; then
185
- provider=$(cat "$CLAUDE_DIR/tts-provider.txt")
186
- elif [[ -f "$HOME/.claude/tts-provider.txt" ]]; then
187
- provider=$(cat "$HOME/.claude/tts-provider.txt")
188
- else
189
- provider="piper"
190
- fi
191
-
192
- local recommended_voice
193
- recommended_voice=$(get_voice_for_language "$lang" "$provider")
194
-
195
- # Fallback to default mapping
196
- if [[ -z "$recommended_voice" ]]; then
197
- recommended_voice=$(_get_language_voice "$lang")
198
- fi
199
-
200
- echo "Current language: $lang"
201
- echo "Recommended voice ($provider): $recommended_voice"
202
- else
203
- echo "Current language: english (default)"
204
- echo "No multilingual voice required"
205
- fi
206
- }
207
-
208
- # Function to get language for use in other scripts
209
- get_language_code() {
210
- if [[ -f "$LANGUAGE_FILE" ]]; then
211
- cat "$LANGUAGE_FILE"
212
- else
213
- echo "english"
214
- fi
215
- }
216
-
217
- # Function to check if current voice supports language
218
- is_voice_multilingual() {
219
- local voice="$1"
220
-
221
- # List of multilingual voices
222
- local multilingual_voices=("Antoni" "Rachel" "Domi" "Bella" "Charlotte" "Matilda")
223
-
224
- for mv in "${multilingual_voices[@]}"; do
225
- if [[ "$voice" == "$mv" ]]; then
226
- return 0
227
- fi
228
- done
229
-
230
- return 1
231
- }
232
-
233
- # Function to get best voice for current language
234
- get_best_voice_for_language() {
235
- local lang=$(get_language_code)
236
-
237
- if [[ "$lang" == "english" ]]; then
238
- # No specific multilingual voice needed for English
239
- echo ""
240
- return
241
- fi
242
-
243
- # Return recommended voice for language
244
- _get_language_voice "$lang"
245
- }
246
-
247
- # Function to get voice for a specific language and provider
248
- # Usage: get_voice_for_language <language> [provider]
249
- # Provider: "piper" or "macos" (auto-detected if not provided)
250
- get_voice_for_language() {
251
- local language="$1"
252
- local provider="${2:-}"
253
-
254
- # Convert to lowercase
255
- language=$(echo "$language" | tr '[:upper:]' '[:lower:]')
256
-
257
- # Auto-detect provider if not specified
258
- if [[ -z "$provider" ]]; then
259
- if command -v get_active_provider &>/dev/null; then
260
- provider=$(get_active_provider 2>/dev/null)
261
- else
262
- # Fallback to checking provider file directly
263
- # Try current directory first, then search up the tree
264
- local search_dir="$PWD"
265
- local found=false
266
-
267
- while [[ "$search_dir" != "/" ]]; do
268
- if [[ -f "$search_dir/.claude/tts-provider.txt" ]]; then
269
- provider=$(cat "$search_dir/.claude/tts-provider.txt")
270
- found=true
271
- break
272
- fi
273
- search_dir=$(dirname "$search_dir")
274
- done
275
-
276
- # If not found in project tree, check global
277
- if [[ "$found" = false ]]; then
278
- if [[ -f "$HOME/.claude/tts-provider.txt" ]]; then
279
- provider=$(cat "$HOME/.claude/tts-provider.txt")
280
- else
281
- provider="piper" # Default
282
- fi
283
- fi
284
- fi
285
- fi
286
-
287
- # Return appropriate voice based on provider (Bash 3.2 compatible)
288
- case "$provider" in
289
- piper)
290
- _get_piper_voice "$language"
291
- ;;
292
- macos)
293
- # macOS doesn't have per-language voices, use default
294
- echo ""
295
- ;;
296
- *)
297
- _get_piper_voice "$language"
298
- ;;
299
- esac
300
- }
301
-
302
- # Main command handler - only run if script is executed directly, not sourced
303
- if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
304
- case "${1:-}" in
305
- set)
306
- if [[ -z "$2" ]]; then
307
- echo "Usage: language-manager.sh set <language>"
308
- exit 1
309
- fi
310
- set_language "$2"
311
- ;;
312
- get)
313
- get_language
314
- ;;
315
- code)
316
- get_language_code
317
- ;;
318
- check-voice)
319
- if [[ -z "$2" ]]; then
320
- echo "Usage: language-manager.sh check-voice <voice-name>"
321
- exit 1
322
- fi
323
- if is_voice_multilingual "$2"; then
324
- echo "yes"
325
- else
326
- echo "no"
327
- fi
328
- ;;
329
- best-voice)
330
- get_best_voice_for_language
331
- ;;
332
- voice-for-language)
333
- if [[ -z "$2" ]]; then
334
- echo "Usage: language-manager.sh voice-for-language <language> [provider]"
335
- exit 1
336
- fi
337
- get_voice_for_language "$2" "$3"
338
- ;;
339
- list)
340
- echo "Supported languages and recommended voices:"
341
- echo ""
342
- # Bash 3.2 compatible - use explicit list instead of associative array keys
343
- # Note: 'local' can't be used outside functions in Bash 3.2
344
- for lang in spanish french german italian portuguese chinese japanese korean russian polish dutch turkish arabic hindi swedish danish norwegian finnish czech romanian ukrainian greek bulgarian croatian slovak; do
345
- printf "%-15s → %s\n" "$lang" "$(_get_language_voice "$lang")"
346
- done | sort
347
- ;;
348
- *)
349
- echo "AgentVibes Language Manager"
350
- echo ""
351
- echo "Usage:"
352
- echo " language-manager.sh set <language> Set language"
353
- echo " language-manager.sh get Get current language"
354
- echo " language-manager.sh code Get language code only"
355
- echo " language-manager.sh check-voice <name> Check if voice is multilingual"
356
- echo " language-manager.sh best-voice Get best voice for current language"
357
- echo " language-manager.sh voice-for-language <lang> [prov] Get voice for language & provider"
358
- echo " language-manager.sh list List all supported languages"
359
- exit 1
360
- ;;
361
- esac
362
- fi
1
+ #!/usr/bin/env bash
2
+ #
3
+ # File: .claude/hooks/language-manager.sh
4
+ #
5
+ # AgentVibes - Finally, your AI Agents can Talk Back! Text-to-Speech WITH personality for AI Assistants!
6
+ # Website: https://agentvibes.org
7
+ # Repository: https://github.com/paulpreibisch/AgentVibes
8
+ #
9
+ # Co-created by Paul Preibisch with Claude AI
10
+ # Copyright (c) 2025 Paul Preibisch
11
+ #
12
+ # Licensed under the Apache License, Version 2.0 (the "License");
13
+ # you may not use this file except in compliance with the License.
14
+ # You may obtain a copy of the License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the License is distributed on an "AS IS" BASIS,
20
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ # See the License for the specific language governing permissions and
22
+ # limitations under the License.
23
+ #
24
+ # DISCLAIMER: This software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
+ # express or implied. Use at your own risk. See the Apache License for details.
26
+ #
27
+ # ---
28
+ #
29
+ # @fileoverview Language Manager - Manages multilingual TTS with 30+ language support
30
+ # @context Enables TTS in multiple languages with provider-specific voice recommendations (Piper native voices)
31
+ # @architecture Dual-map system: PIPER_VOICES for provider-aware voice selection
32
+ # @dependencies provider-manager.sh for active provider detection, .claude/tts-language.txt for state
33
+ # @entrypoints Called by /agent-vibes:language commands, play-tts-*.sh for voice resolution
34
+ # @patterns Provider abstraction, language-to-voice mapping, backward compatibility with legacy LANGUAGE_VOICES
35
+ # @related play-tts-piper.sh, provider-manager.sh, learn-manager.sh
36
+
37
+ # Determine target .claude directory based on context
38
+ # Priority:
39
+ # 1. CLAUDE_PROJECT_DIR env var (set by MCP for project-specific settings)
40
+ # 2. Script location (for direct slash command usage)
41
+ # 3. Global ~/.claude (fallback)
42
+
43
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
44
+
45
+ if [[ -n "${CLAUDE_PROJECT_DIR:-}" ]] && [[ -d "${CLAUDE_PROJECT_DIR:-}/.claude" ]]; then
46
+ # MCP context: Use the project directory where MCP was invoked
47
+ CLAUDE_DIR="$CLAUDE_PROJECT_DIR/.claude"
48
+ else
49
+ # Direct usage context: Use script location
50
+ CLAUDE_DIR="$(cd "$SCRIPT_DIR/.." 2>/dev/null && pwd)"
51
+
52
+ # If script is in global ~/.claude, use that
53
+ if [[ "$CLAUDE_DIR" == "$HOME/.claude" ]]; then
54
+ CLAUDE_DIR="$HOME/.claude"
55
+ elif [[ ! -d "$CLAUDE_DIR" ]]; then
56
+ # Fallback to global if directory doesn't exist
57
+ CLAUDE_DIR="$HOME/.claude"
58
+ fi
59
+ fi
60
+
61
+ LANGUAGE_FILE="$CLAUDE_DIR/tts-language.txt"
62
+ mkdir -p "$CLAUDE_DIR"
63
+
64
+ # Source provider manager to detect active provider
65
+ source "$SCRIPT_DIR/provider-manager.sh" 2>/dev/null || true
66
+
67
+ # =============================================================================
68
+ # BASH 3.2 COMPATIBILITY: Function-based lookups instead of associative arrays
69
+ # macOS ships with Bash 3.2 which doesn't support declare -A (added in Bash 4.0)
70
+ # =============================================================================
71
+
72
+
73
+ # Get Piper voice for a language
74
+ _get_piper_voice() {
75
+ local lang="$1"
76
+ case "$lang" in
77
+ spanish) echo "es_ES-davefx-medium" ;;
78
+ french) echo "fr_FR-siwis-medium" ;;
79
+ german) echo "de_DE-thorsten-medium" ;;
80
+ italian) echo "it_IT-riccardo-x_low" ;;
81
+ portuguese) echo "pt_BR-faber-medium" ;;
82
+ chinese) echo "zh_CN-huayan-medium" ;;
83
+ japanese) echo "ja_JP-hikari-medium" ;;
84
+ korean) echo "ko_KR-eunyoung-medium" ;;
85
+ russian) echo "ru_RU-dmitri-medium" ;;
86
+ polish) echo "pl_PL-darkman-medium" ;;
87
+ dutch) echo "nl_NL-rdh-medium" ;;
88
+ turkish) echo "tr_TR-dfki-medium" ;;
89
+ arabic) echo "ar_JO-kareem-medium" ;;
90
+ hindi) echo "hi_IN-amitabh-medium" ;;
91
+ swedish) echo "sv_SE-nst-medium" ;;
92
+ danish) echo "da_DK-talesyntese-medium" ;;
93
+ norwegian) echo "no_NO-talesyntese-medium" ;;
94
+ finnish) echo "fi_FI-harri-medium" ;;
95
+ czech) echo "cs_CZ-jirka-medium" ;;
96
+ romanian) echo "ro_RO-mihai-medium" ;;
97
+ ukrainian) echo "uk_UA-lada-x_low" ;;
98
+ greek) echo "el_GR-rapunzelina-low" ;;
99
+ bulgarian) echo "bg_BG-valentin-medium" ;;
100
+ croatian) echo "hr_HR-gorana-medium" ;;
101
+ slovak) echo "sk_SK-lili-medium" ;;
102
+ *) echo "" ;;
103
+ esac
104
+ }
105
+
106
+ # Get default (Piper) voice for a language - backward compatibility
107
+ _get_language_voice() {
108
+ _get_piper_voice "$1"
109
+ }
110
+
111
+ # Check if language is supported
112
+ _is_language_supported() {
113
+ local lang="$1"
114
+ local voice
115
+ voice=$(_get_piper_voice "$lang")
116
+ [[ -n "$voice" ]]
117
+ }
118
+
119
+ # Supported languages list
120
+ SUPPORTED_LANGUAGES="spanish, french, german, italian, portuguese, chinese, japanese, korean, polish, dutch, turkish, russian, arabic, hindi, swedish, danish, norwegian, finnish, czech, romanian, ukrainian, greek, bulgarian, croatian, slovak"
121
+
122
+ # Function to set language
123
+ set_language() {
124
+ local lang="$1"
125
+
126
+ # Convert to lowercase
127
+ lang=$(echo "$lang" | tr '[:upper:]' '[:lower:]')
128
+
129
+ # Handle reset/english
130
+ if [[ "$lang" == "reset" ]] || [[ "$lang" == "english" ]] || [[ "$lang" == "en" ]]; then
131
+ if [[ -f "$LANGUAGE_FILE" ]]; then
132
+ rm "$LANGUAGE_FILE"
133
+ echo "✓ Language reset to English (default)"
134
+ else
135
+ echo "Already using English (default)"
136
+ fi
137
+ return 0
138
+ fi
139
+
140
+ # Check if language is supported (Bash 3.2 compatible)
141
+ if ! _is_language_supported "$lang"; then
142
+ echo "❌ Language '$lang' not supported"
143
+ echo ""
144
+ echo "Supported languages:"
145
+ echo "$SUPPORTED_LANGUAGES"
146
+ return 1
147
+ fi
148
+
149
+ # Save language
150
+ echo "$lang" > "$LANGUAGE_FILE"
151
+
152
+ # Detect active provider and get recommended voice
153
+ local provider=""
154
+ if [[ -f "$CLAUDE_DIR/tts-provider.txt" ]]; then
155
+ provider=$(cat "$CLAUDE_DIR/tts-provider.txt")
156
+ elif [[ -f "$HOME/.claude/tts-provider.txt" ]]; then
157
+ provider=$(cat "$HOME/.claude/tts-provider.txt")
158
+ else
159
+ provider="piper"
160
+ fi
161
+
162
+ local recommended_voice
163
+ recommended_voice=$(get_voice_for_language "$lang" "$provider")
164
+
165
+ # Fallback to default mapping if provider-aware function returns empty
166
+ if [[ -z "$recommended_voice" ]]; then
167
+ recommended_voice=$(_get_language_voice "$lang")
168
+ fi
169
+
170
+ echo "✓ Language set to: $lang"
171
+ echo "📢 Recommended voice for $provider TTS: $recommended_voice"
172
+ echo ""
173
+ echo "TTS will now speak in $lang."
174
+ echo "Switch voice with: /agent-vibes:switch \"$recommended_voice\""
175
+ }
176
+
177
+ # Function to get current language
178
+ get_language() {
179
+ if [[ -f "$LANGUAGE_FILE" ]]; then
180
+ local lang=$(cat "$LANGUAGE_FILE")
181
+
182
+ # Detect active provider
183
+ local provider=""
184
+ if [[ -f "$CLAUDE_DIR/tts-provider.txt" ]]; then
185
+ provider=$(cat "$CLAUDE_DIR/tts-provider.txt")
186
+ elif [[ -f "$HOME/.claude/tts-provider.txt" ]]; then
187
+ provider=$(cat "$HOME/.claude/tts-provider.txt")
188
+ else
189
+ provider="piper"
190
+ fi
191
+
192
+ local recommended_voice
193
+ recommended_voice=$(get_voice_for_language "$lang" "$provider")
194
+
195
+ # Fallback to default mapping
196
+ if [[ -z "$recommended_voice" ]]; then
197
+ recommended_voice=$(_get_language_voice "$lang")
198
+ fi
199
+
200
+ echo "Current language: $lang"
201
+ echo "Recommended voice ($provider): $recommended_voice"
202
+ else
203
+ echo "Current language: english (default)"
204
+ echo "No multilingual voice required"
205
+ fi
206
+ }
207
+
208
+ # Function to get language for use in other scripts
209
+ get_language_code() {
210
+ if [[ -f "$LANGUAGE_FILE" ]]; then
211
+ cat "$LANGUAGE_FILE"
212
+ else
213
+ echo "english"
214
+ fi
215
+ }
216
+
217
+ # Function to check if current voice supports language
218
+ is_voice_multilingual() {
219
+ local voice="$1"
220
+
221
+ # List of multilingual voices
222
+ local multilingual_voices=("Antoni" "Rachel" "Domi" "Bella" "Charlotte" "Matilda")
223
+
224
+ for mv in "${multilingual_voices[@]}"; do
225
+ if [[ "$voice" == "$mv" ]]; then
226
+ return 0
227
+ fi
228
+ done
229
+
230
+ return 1
231
+ }
232
+
233
+ # Function to get best voice for current language
234
+ get_best_voice_for_language() {
235
+ local lang=$(get_language_code)
236
+
237
+ if [[ "$lang" == "english" ]]; then
238
+ # No specific multilingual voice needed for English
239
+ echo ""
240
+ return
241
+ fi
242
+
243
+ # Return recommended voice for language
244
+ _get_language_voice "$lang"
245
+ }
246
+
247
+ # Function to get voice for a specific language and provider
248
+ # Usage: get_voice_for_language <language> [provider]
249
+ # Provider: "piper" or "macos" (auto-detected if not provided)
250
+ get_voice_for_language() {
251
+ local language="$1"
252
+ local provider="${2:-}"
253
+
254
+ # Convert to lowercase
255
+ language=$(echo "$language" | tr '[:upper:]' '[:lower:]')
256
+
257
+ # Auto-detect provider if not specified
258
+ if [[ -z "$provider" ]]; then
259
+ if command -v get_active_provider &>/dev/null; then
260
+ provider=$(get_active_provider 2>/dev/null)
261
+ else
262
+ # Fallback to checking provider file directly
263
+ # Try current directory first, then search up the tree
264
+ local search_dir="$PWD"
265
+ local found=false
266
+
267
+ while [[ "$search_dir" != "/" ]]; do
268
+ if [[ -f "$search_dir/.claude/tts-provider.txt" ]]; then
269
+ provider=$(cat "$search_dir/.claude/tts-provider.txt")
270
+ found=true
271
+ break
272
+ fi
273
+ search_dir=$(dirname "$search_dir")
274
+ done
275
+
276
+ # If not found in project tree, check global
277
+ if [[ "$found" = false ]]; then
278
+ if [[ -f "$HOME/.claude/tts-provider.txt" ]]; then
279
+ provider=$(cat "$HOME/.claude/tts-provider.txt")
280
+ else
281
+ provider="piper" # Default
282
+ fi
283
+ fi
284
+ fi
285
+ fi
286
+
287
+ # Return appropriate voice based on provider (Bash 3.2 compatible)
288
+ case "$provider" in
289
+ piper)
290
+ _get_piper_voice "$language"
291
+ ;;
292
+ macos)
293
+ # macOS doesn't have per-language voices, use default
294
+ echo ""
295
+ ;;
296
+ *)
297
+ _get_piper_voice "$language"
298
+ ;;
299
+ esac
300
+ }
301
+
302
+ # Main command handler - only run if script is executed directly, not sourced
303
+ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
304
+ case "${1:-}" in
305
+ set)
306
+ if [[ -z "$2" ]]; then
307
+ echo "Usage: language-manager.sh set <language>"
308
+ exit 1
309
+ fi
310
+ set_language "$2"
311
+ ;;
312
+ get)
313
+ get_language
314
+ ;;
315
+ code)
316
+ get_language_code
317
+ ;;
318
+ check-voice)
319
+ if [[ -z "$2" ]]; then
320
+ echo "Usage: language-manager.sh check-voice <voice-name>"
321
+ exit 1
322
+ fi
323
+ if is_voice_multilingual "$2"; then
324
+ echo "yes"
325
+ else
326
+ echo "no"
327
+ fi
328
+ ;;
329
+ best-voice)
330
+ get_best_voice_for_language
331
+ ;;
332
+ voice-for-language)
333
+ if [[ -z "$2" ]]; then
334
+ echo "Usage: language-manager.sh voice-for-language <language> [provider]"
335
+ exit 1
336
+ fi
337
+ get_voice_for_language "$2" "$3"
338
+ ;;
339
+ list)
340
+ echo "Supported languages and recommended voices:"
341
+ echo ""
342
+ # Bash 3.2 compatible - use explicit list instead of associative array keys
343
+ # Note: 'local' can't be used outside functions in Bash 3.2
344
+ for lang in spanish french german italian portuguese chinese japanese korean russian polish dutch turkish arabic hindi swedish danish norwegian finnish czech romanian ukrainian greek bulgarian croatian slovak; do
345
+ printf "%-15s → %s\n" "$lang" "$(_get_language_voice "$lang")"
346
+ done | sort
347
+ ;;
348
+ *)
349
+ echo "AgentVibes Language Manager"
350
+ echo ""
351
+ echo "Usage:"
352
+ echo " language-manager.sh set <language> Set language"
353
+ echo " language-manager.sh get Get current language"
354
+ echo " language-manager.sh code Get language code only"
355
+ echo " language-manager.sh check-voice <name> Check if voice is multilingual"
356
+ echo " language-manager.sh best-voice Get best voice for current language"
357
+ echo " language-manager.sh voice-for-language <lang> [prov] Get voice for language & provider"
358
+ echo " language-manager.sh list List all supported languages"
359
+ exit 1
360
+ ;;
361
+ esac
362
+ fi