feat(voice): add CLI args for extra player args, TTS provider, and port#323
feat(voice): add CLI args for extra player args, TTS provider, and port#323sti0 wants to merge 2 commits into
Conversation
97a51fa to
09a326b
Compare
Adds three new CLI flags to the voice server: - --extra-args: Pass additional arguments to audio players (e.g., "-o pulse") - --tts-provider: Select TTS provider (google/elevenlabs) - --port: Configure server port Also includes fix for argument ordering - extra args now correctly precede the filename so audio players recognize them. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
09a326b to
775c937
Compare
The .env parser was keeping literal quote characters when values were
quoted (e.g., VOICE_SERVER_EXTRA_ARGS="-o pulse"). This caused mpg123
to receive broken arguments like '"-o' 'pulse"' instead of '-o' 'pulse'.
Changes:
- Use indexOf('=') instead of split('=') to handle values containing '='
- Strip surrounding double and single quotes from values
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
suggest adding --host / PAI_VOICE_HOST overrides too. It's on my list but you already did all this in here! I'll add it later on if you don't want to though. |
Hi @ecielam , Correct me if I'm wrong. If so, feel free to contribute this feature in a different branch. There should be no blocking involved. BR |
yeah, you're right it's technically a new feature ... I'll contribute later once your stuff is merged in and I get around to doing it. |
|
Thank you @sti0 for these voice CLI improvements! 🙏 With PAI v2.1, all packs moved to See the release: https://github.com/danielmiessler/PAI/releases/tag/v2.1.0 |
Description
Overview
Adds configuration options for passing extra arguments to audio players, overriding the TTS provider, and setting the server port via CLI flags. This enables voice notifications to work inside devcontainers and other containerized environments where audio requires special configuration (e.g., PulseAudio socket mounting).
Problem
The voice server previously:
/usr/bin/mpg123,/snap/bin/mpv) that don't work when players are installed elsewhere-o pulsein containers)whichon every audio playback instead of caching the resultSolution
New CLI Flags
--extra-args=<args>--tts-provider=<provider>-t--port=<port>-pNew Environment Variable
VOICE_SERVER_EXTRA_ARGSDynamic Player Detection (Cached)
Replaced hardcoded paths with
which-based detection, cached at startup:detectPlayer()runs once at startup, stores result inDETECTED_PLAYERfindPlayer('mpg123')/findPlayer('mpv')- finds player regardless of install locationwhichcalls during audio playbackChanges
Packs/kai-voice-system/src/voice/server.tsImports & CLI Parsing:
parseArgsimport from Node.jsutilmoduleexecSyncimport for runningwhichcommands--extra-args,--tts-provider/-t,--port/-pcliArgs.values.port || process.env.PAI_VOICE_PORT || "8888"Player Detection:
findPlayer(name)function for dynamic player detection viawhichdetectPlayer()function that runs once at startupDETECTED_PLAYERconstant caching the detected player path and typeplayAudio()to use cachedDETECTED_PLAYERinstead of callingfindPlayer()repeatedlyConfiguration Functions:
getExtraArgs()function to resolve CLI/env args with precedenceTTS_PROVIDERto accept CLI override via--tts-provider/-tLogging:
Packs/kai-voice-system/README.mdUsage Examples
Environment Variable:
CLI Flags:
Devcontainer Setup:
{ "mounts": [ "source=/run/user/1000/pulse,target=/run/user/1000/pulse,type=bind" ], "containerEnv": { "PULSE_SERVER": "unix:/run/user/1000/pulse/native" } }Common Use Cases
VOICE_SERVER_EXTRA_ARGS="-o pulse"VOICE_SERVER_EXTRA_ARGS="-o alsa -a hw:1,0"--tts-provider=googleor-t google--port=9000or-p 9000Logging Output
Startup: Shows detected player and configured extra args
Runtime: Logs full player command when extra args are used
Test Plan
VOICE_SERVER_EXTRA_ARGS="-o pulse"- verify startup log shows extra args--extra-args="-o alsa"- verify CLI overrides env var--tts-provider=google- verify TTS provider switches-t elevenlabs- verify short flag works--port=9000- verify server starts on port 9000-p 9000- verify short flag works for portfindPlayer()locates mpg123/mpv correctly on LinuxBreaking Changes
None. All changes are additive and backward compatible.
Dependencies
This depends partially on #322 where
.envloading was enhanced.Generated with Claude Code