Metadata-Version: 2.5
Name: vcbot
Version: 0.0.2
Summary: Discord voice selfbot with local Whisper streaming transcription and TTS playback.
Keywords: discord,selfbot,transcription,tts,voice,whisper
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Requires-Python: >=3.11
Requires-Dist: audioop-lts>=0.2.2; python_version >= '3.13'
Requires-Dist: ctranslate2<5,>=4.5
Requires-Dist: davey==0.1.0
Requires-Dist: discord-py-self[voice]==2.1.0
Requires-Dist: faster-whisper==1.2.1
Requires-Dist: librosa
Requires-Dist: numpy>=1.26
Requires-Dist: pynacl<1.6,>=1.5
Requires-Dist: scipy
Requires-Dist: soundfile
Requires-Dist: yt-dlp
Provides-Extra: cuda
Requires-Dist: cuda-bindings<14,>=12.8; extra == 'cuda'
Requires-Dist: nvidia-cublas-cu12; extra == 'cuda'
Requires-Dist: nvidia-cudnn-cu12; extra == 'cuda'
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: setuptools>=68; extra == 'dev'
Description-Content-Type: text/markdown

# Discord voice selfbot

Play local audio, YouTube, or SoundCloud in a voice call, speak text with
eSpeak, and record and transcribe other participants locally with WhisperStreaming.

## Setup

Use Python 3.11 or newer. Install FFmpeg for
link playback and other audio formats, eSpeak NG (or eSpeak) for `>tts`, and
the Opus shared library for voice. On Debian or Ubuntu:

```sh
sudo apt install ffmpeg espeak-ng libopus0 python3-venv
python3 -m venv .venv
make install                 # or: .venv/bin/pip install -e ".[dev]"
```

`make install` creates the virtualenv if needed and installs the project in
editable mode, which also puts the `vcbot` command on the environment's `PATH`.

CPU transcription needs no CUDA libraries. For NVIDIA GPU transcription,
install CUDA 12 cuBLAS and cuDNN 9. On Linux or WSL, the bot loads them
from the system or from NVIDIA's wheels installed in the same Python
environment:

```sh
make install-cuda            # or: .venv/bin/pip install -e ".[cuda]"
```

On Windows, make the CUDA and cuDNN DLLs available on `PATH`.

Set `DISCORD_USER_TOKEN` in the environment and run `vcbot`. From a checkout that
is not installed, `python -m vcbot` is equivalent.
Keep the token out of source files and shell history. This program signs in
as a user account; Discord prohibits selfbots on its platform.

## Startup options

Run `vcbot --help` to see every option. Flags override environment
variables, which override built-in defaults. Leave the token in
`DISCORD_USER_TOKEN` when possible; a token passed as `--discord-user-token`
(`--token`) can appear in shell history and in the process list.

```sh
vcbot --whisper-backend cpu --whisper-model base --whisper-streams 1
vcbot --prefix '!' --reply-delete-after 30 --recordings-dir ./voice-logs --debug
```

| Flag | Environment variable | Default |
| --- | --- | --- |
| `--discord-user-token` | `DISCORD_USER_TOKEN` | Required |
| `--prefix` | `SELFBOT_PREFIX` | `>` |
| `--reply-delete-after` | `SELFBOT_REPLY_DELETE_AFTER` | 20 seconds |
| `--voice-timeout` | `SELFBOT_VOICE_TIMEOUT` | 20 seconds |
| `--tts-voice` | `SELFBOT_TTS_VOICE` | `en-us+whisper` |
| `--tts-speed`, `--tts-pitch`, `--tts-amplitude` | `SELFBOT_TTS_SPEED`, `SELFBOT_TTS_PITCH`, `SELFBOT_TTS_AMPLITUDE` | eSpeak defaults; each `>tts` call can override them |
| `--recordings-dir` | `SELFBOT_RECORDINGS_DIR` | `./recordings` |
| `--whisper-model` | `WHISPER_MODEL` | `turbo` |
| `--whisper-language` (`--whisper-lang`) | `WHISPER_LANGUAGE` | `en`; `auto` detects the language on every chunk |
| `--whisper-vad` / `--no-whisper-vad` | `WHISPER_VAD=1` | Off; runs Silero VAD on each chunk to drop non-speech |
| `--whisper-backend` (`--whisper-device`) | `WHISPER_BACKEND` | `auto` (CUDA if visible, otherwise CPU); also accepts `cpu` and `cuda` |
| `--whisper-streams` | `WHISPER_STREAMS` | 2 on CPU or 4 on CUDA |
| `--whisper-workers` | `WHISPER_WORKERS` | Available logical CPUs, capped at 32 by default |
| `--whisper-vram-percent` | `WHISPER_VRAM_PERCENT` | 75% (CUDA only) |
| `--whisper-chunk-seconds` | `WHISPER_CHUNK_SECONDS` | 2 seconds (1–10) |
| `--whisper-pause-seconds` | `WHISPER_PAUSE_SECONDS` | 1 second |
| `--debug` / `--no-debug` | `SELFBOT_DEBUG=1` | Off |

## Commands

Type these as regular messages. Replies, including help and transcript
attachments, are visible in the conversation before being deleted after
about 20 seconds. Only the signed-in account can run commands directly;
other users can invoke `@mention >tts ...`.

| Command | What it does |
| --- | --- |
| `>help`, `>ping` | Show command help or gateway latency. |
| `>join [voice channel or link]` or `>join <server_id> <channel_id>` | Join the current DM/group call or a server voice channel. Links and ID pairs work from outside that server. |
| `>vc_active` | Show which voice session this conversation controls, including connection, playback, and recording status. |
| `>vc_list` | List who is connected and whether each person is muted or deafened. Uses the current voice channel's chat, your connected channel in the server, or the active DM/group call. |
| `>diagnostics` | Check gateway and voice connectivity, local tools, and recording packet and queue counts. |
| `>tts [options] <text>` | Speak text in the active call. |
| `>voices [query]` | List or filter installed voices and variants. |
| `>play <url or path>` | Play a public YouTube or SoundCloud link, or an audio file on the machine running the bot. Links use yt-dlp and FFmpeg. |
| `>pause`, `>resume`, `>skip` | Control active playback. Recording continues independently. |
| `>models` | List the model names accepted by `>record`, including models that download on first use. |
| `>record [--language <code\|auto>] [--vad\|--no-vad] [model]` | Start recording and transcribing the active call. The language defaults to the configured `en` and skips per-chunk language detection. VAD defaults to the configured value. |
| `>vad` | Toggle Silero VAD on or off. Applies to the active recording immediately and becomes the default for later recordings. |
| `>log <n>` | Show the last `n` lines of the current or latest transcript. Long results are sent as an attachment. |
| `>stop` | Finish writing the recording and transcript without leaving voice. |
| `>leave` | Disconnect immediately. Any active recording keeps finalizing its transcript in the background; use `>stop` first if you want to wait for it. |

In a server, try `>join General Voice` or pass a channel mention or ID. With
no argument, `>join` uses the voice channel whose chat you are typing in
or the channel the signed-in account is currently in. To join from another
server or a private conversation, send `>join <server_id> <channel_id>` or
`>join https://discord.com/channels/<server_id>/<channel_id>`. The signed-in
account needs access to that channel. After a remote join, you can run voice
commands in the conversation that started the join or in the destination
server. Replies (including `>vc_list` and `>log`) appear where you run the
command. Run `>join` for a local channel or call to switch that conversation
back to local controls.

TTS options go before the text: `--voice` (`-v`, default `en-us+whisper`),
`--speed` (`-s`, 80–450 words per minute), `--pitch` (`-p`, 0–99), and
`--amplitude` (`-a`, 0–200). Example: `>tts --voice fr --speed 140 Bonjour`.
Loud playback and TTS leave 6 dB of peak headroom before Opus encoding.
Recording also leaves 6 dB of headroom inside the Opus decoder before saving
16-bit WAV files.

## Troubleshooting

- Run `>ping` to verify commands are reaching the bot. Run `>vc_active` to see
  where voice commands will go. If Discord shows you in voice but the bot has
  no connection, run `>join` to establish its audio session.
- Run `>diagnostics` while recording to see whether voice packets arrive and
  decode. The decoded count excludes Discord's silence packets; a low count
  while nobody is speaking is normal. Opus may report "not loaded yet" before
  the first use.
- Start with `vcbot --debug` for command, voice, playback,
  and recording logs in the terminal.

## Recording

WhisperStreaming runs a separate online processor for each speaker. During
continuous speech it receives audio about every two seconds by default, confirms words
that agree across successive passes, and trims completed segments to keep the
working audio window short. A pause, speaker disconnect, or recording stop
flushes any remaining words. WhisperStreaming uses faster-whisper and
CTranslate2 as its local inference engine on CPU and CUDA.

Use `>record base` for a lighter model, especially on CPU. Model selection
follows the command argument, then the configured default (`turbo`). The
first use of a model may download its CTranslate2 weights from Hugging Face;
previous OpenAI Whisper `.pt` files are not used. `WHISPER_STREAMS` caps the
total number of loaded or loading Whisper instances across all calls and
model names in the process. The default is 2 on CPU or 4 on CUDA. Set it
to 1 if RAM or VRAM is limited. Idle instances are reused or evicted if
another model needs their slot.

Whisper detects the spoken language separately on every chunk unless one is
given. Set `--whisper-language es` (or `WHISPER_LANGUAGE`) to make that the
default for every recording, or pass `>record --language es` to override it
for one session. Use `auto` to keep detecting. Fixing the language removes
the detection pass from each inference, and `>vc_active` and
`>diagnostics` show the language in use. English-only models (`base.en` and
similar) only accept `en` (or `auto`, which still transcribes as English).

Voice activity detection is off by default. Set `--whisper-vad` (or
`WHISPER_VAD=1`) to run faster-whisper's bundled Silero VAD over each chunk
and drop non-speech before transcription, which avoids hallucinated lines on
music, noise, or silence. Pass `>record --vad` or `>record --no-vad` to
override it for one session. This is the vendored `--vad` option; the
vendored `--vac` option is not ported because it expects 40 ms chunks and
downloads a Torch model, while this bot already splits audio per speaker and
flushes on pauses. VAD state appears in `>vc_active` and `>diagnostics`.

The transcription worker pool is sized separately, using the logical CPUs
available to the process (at least 1 and at most 32). On CUDA, model
admission also targets 75% of total GPU memory by default. Set
`WHISPER_VRAM_PERCENT` to a whole number from 1 to 100 to change that target.
The check accounts for other GPU usage and reserves an estimated inference
footprint for each Whisper instance, including loads in progress. The
effective instance limit can therefore be lower than `WHISPER_STREAMS`.
The budget is an estimate: inference peaks and memory changes in other
processes can still cause higher usage. It does not apply to CPU recording.

Each session writes `<session>/transcript.txt` under the recordings directory and
`<user_id>.wav` tracks in the same directory. The WAVs contain captured
speech chunks at 48 kHz stereo; they omit gaps with no received audio.
Silence, near-silence, and brief spikes are skipped before Whisper
inference; captured audio is still saved to the WAV tracks. Processed
lines appear in the terminal as well as the transcript. Each call can queue
up to 32 audio chunks or 60 seconds of audio, whichever fills first. Under
sustained load, the recorder continues saving WAVs and skips new transcription
work when the queue is full. `>diagnostics` shows the skipped audio duration.
`>stop` waits for queued transcription to finish. Record only with
participants' knowledge and permission.

## Packaging

The project is a PEP 517 package built with hatchling, so `pip install .` and
`uv build` both work. `vcbot` is a console script (`vcbot = "vcbot.cli:main"`)
and `python -m vcbot` runs the same entry point; the version lives in
`vcbot/__init__.py`.

```sh
make build      # dist/vcbot-<version>.tar.gz and dist/vcbot-<version>-py3-none-any.whl
make check      # build, install the wheel in a scratch venv, run --version and --help
```

`make test` runs the unit tests with `unittest`; `make lint` runs ruff over the
package, with the vendored WhisperStreaming code excluded.

`setup.py` is a shim for tooling that still expects one: it reads every field
back out of `pyproject.toml` at build time, so it cannot drift. `pyproject.toml`
remains authoritative and hatchling remains the build backend.

### Continuous integration

`.github/workflows/ci.yml` runs on every push to `master` and on pull requests:

- **lint** — ruff over `vcbot/` and `setup.py`.
- **test** — the unit tests, the console script and `python -m vcbot` on Python
  3.11, 3.12 and 3.13.
- **package** — builds the sdist and wheel, installs each into a throwaway
  environment, then checks the wheel layout (no tests, vendored `LICENSE`
  present, `vcbot = vcbot.cli:main`) and that `setup.py` reports the same name
  and version as the package.

Pushing a `v*` tag runs `.github/workflows/release.yml`, which refuses to
publish unless the tag matches `vcbot/__init__.py`, then attaches the built
artefacts to a GitHub release.

## Code layout

Everything below lives in the `vcbot/` package.

- `cli.py` parses the command line and then imports the application, so
  `--help` and argument errors never load Discord or Whisper.
- `config.py` defines startup options, environment fallbacks, and defaults.
- `main.py` registers commands, handles voice connections and playback
  reservations, and sets the reply deletion timer.
- `speech.py` prepares audio from eSpeak, local files, or yt-dlp links.
- `transcription.py` receives Discord voice packets, segments audio, and
  writes WAVs and transcripts using bounded Whisper concurrency. While
  recording, it keeps the voice UDP socket active through quiet periods.
- `whisper_backend.py` connects WhisperStreaming processors to the shared
  model pool and checks CUDA VRAM.
- `vendor/whisper_streaming/` contains the online WhisperStreaming module and license
  derived from [WhisperStreaming revision `6da90b4`](https://github.com/ufal/whisper_streaming/tree/6da90b44b7e50d79695e68166d2a2c7609c75abb).
