# Local Command STT Wrapper Template

## Required Env Var

```bash
export HERMES_LOCAL_STT_COMMAND="/path/to/wrapper.sh {input_path} {model} {output_dir} {language}"
```

## Wrapper Script Requirements

The wrapper script receives four positional arguments:
1. `input_path` - path to the audio file (e.g. `.ogg` from Telegram)
2. `model` - model name from config (e.g. `base`)
3. `output_dir` - directory where transcript.txt must be written
4. `language` - language code (e.g. `de`)

The script must:
- Convert audio to WAV (16kHz mono) if needed
- Run transcription
- Write transcript to `{output_dir}/transcript.txt`
- Print transcript to stdout (optional, for logging)
- Exit 0 on success, non-zero on failure

## Example: faster-whisper Wrapper

```bash
#!/bin/sh
# /opt/data/stt-wrapper.sh
# Wrapper for Hermes local_command STT (faster-whisper)

INPUT_PATH="$1"
MODEL="$2"
OUTPUT_DIR="$3"
LANGUAGE="$4"

# Ensure Python can find faster-whisper (adjust path as needed)
export PYTHONPATH=/opt/data/home/.local/lib/python3.14/site-packages

exec /usr/local/bin/python3 -c "
import subprocess, sys, os, tempfile
input_file = sys.argv[1]
output_dir = sys.argv[3]
language = sys.argv[4]
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp:
    wav_path = tmp.name
subprocess.run(['ffmpeg', '-y', '-i', input_file, '-ar', '16000', '-ac', '1', wav_path], capture_output=True, check=True)
from faster_whisper import WhisperModel
model = WhisperModel('base', device='cpu', compute_type='int8')
segments, info = model.transcribe(wav_path, language=language)
text = ' '.join([s.text for s in segments]).strip()
out_file = os.path.join(output_dir, 'transcript.txt')
with open(out_file, 'w', encoding='utf-8') as f:
    f.write(text)
print(text)
os.unlink(wav_path)
" "$INPUT_PATH" "$MODEL" "$OUTPUT_DIR" "$LANGUAGE"
```

## Key Points

- **Make it executable**: `chmod +x /path/to/wrapper.sh`
- **ffmpeg must be available** in PATH for audio conversion
- **Python path** must include the site-packages where faster-whisper is installed
- **The `{output_dir}` is a temp directory** created by Hermes per transcription request
- **Language handling**: The script should pass the language to Whisper; empty/None lets Whisper auto-detect

## For s6/Container Deployments

```bash
# Set in container environment
echo '/path/to/wrapper.sh {input_path} {model} {output_dir} {language}' > /run/s6/container_environment/HERMES_LOCAL_STT_COMMAND

# Or in service env directory (and ensure run script sources it)
mkdir -p /run/service/gateway-default/env
echo '/path/to/wrapper.sh {input_path} {model} {output_dir} {language}' > /run/service/gateway-default/env/HERMES_LOCAL_STT_COMMAND
```

The service run script should source env vars from the env directory:
```bash
if [ -d /run/service/gateway-default/env ]; then
    for f in /run/service/gateway-default/env/*; do
        [ -f "$f" ] && export "$(basename "$f")=$(cat "$f")"
    done
fi
```

## Disable Transcript Echo

To prevent Hermes from sending the transcript as a separate message before the agent reply:

```bash
hermes config set stt.echo_transcripts false
```

Or in config.yaml:
```yaml
stt:
  echo_transcripts: false
```