vcbot 0.1.0__tar.gz
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.
- vcbot-0.1.0/.gitignore +12 -0
- vcbot-0.1.0/DOCUMENTATION.md +216 -0
- vcbot-0.1.0/Makefile +52 -0
- vcbot-0.1.0/PKG-INFO +268 -0
- vcbot-0.1.0/README.md +231 -0
- vcbot-0.1.0/pyproject.toml +96 -0
- vcbot-0.1.0/requirements.txt +20 -0
- vcbot-0.1.0/setup.py +58 -0
- vcbot-0.1.0/vcbot/__init__.py +3 -0
- vcbot-0.1.0/vcbot/__main__.py +6 -0
- vcbot-0.1.0/vcbot/cli.py +22 -0
- vcbot-0.1.0/vcbot/config.py +319 -0
- vcbot-0.1.0/vcbot/main.py +815 -0
- vcbot-0.1.0/vcbot/speech.py +319 -0
- vcbot-0.1.0/vcbot/test_transcription.py +527 -0
- vcbot-0.1.0/vcbot/transcription.py +689 -0
- vcbot-0.1.0/vcbot/vendor/__init__.py +6 -0
- vcbot-0.1.0/vcbot/vendor/whisper_streaming/LICENSE +21 -0
- vcbot-0.1.0/vcbot/vendor/whisper_streaming/__init__.py +1 -0
- vcbot-0.1.0/vcbot/vendor/whisper_streaming/whisper_online.py +1048 -0
- vcbot-0.1.0/vcbot/whisper_backend.py +261 -0
vcbot-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# Reference documentation
|
|
2
|
+
|
|
3
|
+
Fetched digests of the upstream documentation this project depends on, plus the
|
|
4
|
+
contracts that are **not** written down anywhere upstream and therefore had to be
|
|
5
|
+
recovered from source. Versions the notes below describe:
|
|
6
|
+
|
|
7
|
+
| package | version |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| discord.py-self | 2.1.0 |
|
|
10
|
+
| faster-whisper | 1.2.1 |
|
|
11
|
+
| ctranslate2 | 4.9.1 |
|
|
12
|
+
| davey | 0.1.0 |
|
|
13
|
+
| PyNaCl | 1.5.0 |
|
|
14
|
+
|
|
15
|
+
Sources:
|
|
16
|
+
|
|
17
|
+
- https://discordpy-self.readthedocs.io/en/latest/
|
|
18
|
+
- https://deepwiki.com/dolfies/discord.py-self
|
|
19
|
+
- https://deepwiki.com/ufal/whisper_streaming
|
|
20
|
+
- https://github.com/SYSTRAN/faster-whisper
|
|
21
|
+
- https://deepwiki.com/dolfies/discord-native-voice
|
|
22
|
+
|
|
23
|
+
Reading them locally: `source .venv/bin/activate` is broken in this worktree (the
|
|
24
|
+
venv is uv-managed CPython 3.13, `python` on PATH is 3.14, so activation silently
|
|
25
|
+
does nothing). Use `.venv/bin/python` directly, and use `inspect.signature` on the
|
|
26
|
+
installed packages — for the receive path it is more authoritative than the docs.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## discord.py-self
|
|
31
|
+
|
|
32
|
+
**What it covers.** Client/gateway/HTTP, data models, command framework, and a
|
|
33
|
+
Voice System section split into *Voice Clients and Connection*, *Audio Players and
|
|
34
|
+
Sources*, *Opus Encoding*, *Voice Encryption*. It is a playback-oriented API doc:
|
|
35
|
+
everything about voice is about **sending**.
|
|
36
|
+
|
|
37
|
+
**What matters here.** `VoiceClient.supported_modes` is the class-level tuple the
|
|
38
|
+
client offers during negotiation. Negotiation order: the voice gateway `READY`
|
|
39
|
+
payload advertises `modes` → `initial_connection()` intersects them with
|
|
40
|
+
`supported_modes` and sends `SELECT_PROTOCOL` → `SESSION_DESCRIPTION` returns the
|
|
41
|
+
selected mode and `secret_key`. `VoiceClient.mode`, `.ssrc`, `.secret_key` are
|
|
42
|
+
properties backed by the connection state.
|
|
43
|
+
|
|
44
|
+
**What it does not cover.** There is no documented receive API. The usable hook is
|
|
45
|
+
on the connection state, not the client:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
state = voice_client._connection # VoiceConnectionState
|
|
49
|
+
state.add_socket_listener(callback) # callback(packet: bytes), raw UDP datagram
|
|
50
|
+
state.remove_socket_listener(callback) # reading pauses when the last one goes
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`VoiceConnectionState` owns the non-blocking UDP socket, the voice websocket,
|
|
54
|
+
ssrc, negotiated mode, `secret_key`, and the optional `dave_session` /
|
|
55
|
+
`dave_protocol_version`. `send_packet()` is the outgoing path; the listener
|
|
56
|
+
callbacks are the incoming path. Nothing in the library parses incoming RTP or
|
|
57
|
+
decodes incoming Opus for you — this project does both in
|
|
58
|
+
`vcbot/transcription.py:541` (`_decode`).
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Receive path contract (recovered, not documented upstream)
|
|
63
|
+
|
|
64
|
+
Inverse of the documented outgoing packet: `header + ciphertext(+tag) + nonce[:4]`.
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
byte 0 V/P/X/CC bits byte 1 M/PT
|
|
68
|
+
bytes 2-3 sequence bytes 4-7 timestamp
|
|
69
|
+
bytes 8-11 ssrc
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`aead_xchacha20_poly1305_rtpsize`:
|
|
73
|
+
|
|
74
|
+
1. `header_size = 12 + 4 * (packet[0] & 0x0F)`.
|
|
75
|
+
2. If `packet[0] & 0x10` (extension bit): a 4-byte preamble sits at
|
|
76
|
+
`header_size`; the extension **length** is the big-endian u16 at
|
|
77
|
+
`header_size + 2`, in 4-byte words, and `header_size += 4`. The extension
|
|
78
|
+
*values* are inside the ciphertext, not the header.
|
|
79
|
+
3. `nonce = packet[-4:] + bytes(20)` — a 4-byte counter plus 20 zero bytes, i.e.
|
|
80
|
+
the 24-byte nonce XChaCha20-Poly1305 requires.
|
|
81
|
+
4. `payload = Aead(secret_key).decrypt(packet[header_size:-4],
|
|
82
|
+
aad=packet[:header_size], nonce=nonce)`. The header, including the extension
|
|
83
|
+
preamble, is authenticated as associated data. PyNaCl 1.5.0's
|
|
84
|
+
`Aead.decrypt(ciphertext, aad=b'', nonce=None, encoder=...)` does take the
|
|
85
|
+
nonce — the 2-argument form in older examples is only valid at construction
|
|
86
|
+
time.
|
|
87
|
+
5. Strip the extension bytes: `opus = payload[extension_size:]`.
|
|
88
|
+
6. If `packet[0] & 0x20` (padding bit): `opus = opus[:-opus[-1]]`.
|
|
89
|
+
7. Discard the 3-byte comfort-noise/silence frame `b"\xf8\xff\xfe"`.
|
|
90
|
+
8. DAVE, when `dave_protocol_version` is set: the session must exist and be
|
|
91
|
+
`ready`, then `opus = session.decrypt(user_id, davey.MediaType.audio, opus)`.
|
|
92
|
+
9. `discord.opus.Decoder.decode(opus)` → 48 kHz stereo s16 PCM.
|
|
93
|
+
|
|
94
|
+
Sequence numbers are per-SSRC and wrap; after an idle gap longer than
|
|
95
|
+
`RTP_RESYNC_SECONDS` the baseline is re-taken (only once a packet authenticates).
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## discord-native-voice (deepwiki)
|
|
100
|
+
|
|
101
|
+
**What it covers.** The Rust/PyO3 replacement client: transport, IP discovery,
|
|
102
|
+
encryption, RTP module, video pipeline, packaging.
|
|
103
|
+
|
|
104
|
+
**What it is good for.** Confirming the wrapper-level DAVE call shapes and the
|
|
105
|
+
generic `encrypt(media_type, codec, payload)` / `decrypt(user_id, media_type,
|
|
106
|
+
payload)` argument order.
|
|
107
|
+
|
|
108
|
+
**What it is not good for.** It does not document the MLS group lifecycle, the
|
|
109
|
+
gateway opcodes (25 key package, 26 prepare transition, 21 …), or the DAVE
|
|
110
|
+
supplement framing — asked directly, it answers "not shown in this context". For
|
|
111
|
+
those, use the code path below rather than the wiki.
|
|
112
|
+
|
|
113
|
+
Verified `davey` 0.1.0 surface:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
DaveSession.encrypt_opus(packet)
|
|
117
|
+
DaveSession.encrypt(media_type, codec, packet)
|
|
118
|
+
DaveSession.decrypt(user_id, media_type, packet)
|
|
119
|
+
DaveSession.set_passthrough_mode(passthrough_mode, transition_expiry=None)
|
|
120
|
+
DaveSession.process_proposals(operation_type, proposals, expected_user_ids=None)
|
|
121
|
+
DaveSession.process_commit(commit) / process_welcome(welcome)
|
|
122
|
+
DaveSession.get_serialized_key_package() / get_user_ids() / .ready
|
|
123
|
+
MediaType.audio|video Codec.opus|av1|h264|h265|vp8|vp9|unknown
|
|
124
|
+
SessionStatus.inactive|pending|awaiting_response|active
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## faster-whisper
|
|
130
|
+
|
|
131
|
+
**Constructor.**
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
WhisperModel(model_size_or_path, device="auto", compute_type="default",
|
|
135
|
+
cpu_threads=0, num_workers=1, download_root=None, local_files_only=False)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`cpu_threads=0` means "CTranslate2 machine-wide default", not "one thread" — every
|
|
139
|
+
instance loaded that way claims the whole machine, and several instances then
|
|
140
|
+
oversubscribe each other. `vcbot/whisper_backend.py` therefore passes
|
|
141
|
+
`_cpu_threads()` = `worker_count() // min(whisper_streams, workers)`.
|
|
142
|
+
|
|
143
|
+
Quantisation: `float16` / `int8_float16` on CUDA, `int8` on CPU (CPU is `float32`
|
|
144
|
+
by default in this project's loader only because it was never pinned — `int8` is
|
|
145
|
+
2.5-4× faster and uses less RAM). README benchmarks, large-v2, beam 5: fp16 1m03s,
|
|
146
|
+
int8 59s, int8 with `batch_size=8` 16s — batching is the large win, but a
|
|
147
|
+
per-speaker FIFO stream cannot use it.
|
|
148
|
+
|
|
149
|
+
**`transcribe()` defaults (1.2.1).**
|
|
150
|
+
|
|
151
|
+
| parameter | default |
|
|
152
|
+
| --- | --- |
|
|
153
|
+
| `language` | `None` (auto-detect) |
|
|
154
|
+
| `beam_size` | `5` |
|
|
155
|
+
| `word_timestamps` | `False` |
|
|
156
|
+
| `condition_on_previous_text` | `True` |
|
|
157
|
+
| `vad_filter` | `False` |
|
|
158
|
+
| `initial_prompt` | `None` |
|
|
159
|
+
| `without_timestamps` | `False` |
|
|
160
|
+
|
|
161
|
+
`segments` is a **generator**: transcription happens on iteration, so a caller
|
|
162
|
+
that only keeps the generator does no work. The streaming backend forces
|
|
163
|
+
`beam_size=1` in its `transcribe` override because each pass re-transcribes the
|
|
164
|
+
whole buffer and later passes overwrite earlier output; `word_timestamps=True` is
|
|
165
|
+
kept because `ts_words` / `HypothesisBuffer` need word-level hypotheses.
|
|
166
|
+
|
|
167
|
+
`vad_filter=True` uses Silero VAD and by default only removes silences longer than
|
|
168
|
+
2 s; tune with `vad_parameters=dict(min_silence_duration_ms=500)`.
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
## whisper_streaming (deepwiki)
|
|
173
|
+
|
|
174
|
+
**Core.**
|
|
175
|
+
`OnlineASRProcessor.process_iter()` returns `(begin_time, end_time, text)` for
|
|
176
|
+
**newly committed** words, or `(None, None, "")`. Each call re-transcribes the
|
|
177
|
+
**entire retained `audio_buffer`** — so cost scales with how much audio is still
|
|
178
|
+
buffered, which is why buffer trimming and push rate, not the number of model
|
|
179
|
+
instances, set throughput.
|
|
180
|
+
|
|
181
|
+
`HypothesisBuffer` keeps continuity: `insert()` shifts ASR timestamps by
|
|
182
|
+
`buffer_time_offset`, drops words at or before `last_commited_time - 0.1`, and
|
|
183
|
+
suppresses a repeated prefix of up to five words near the previous commit
|
|
184
|
+
boundary. `flush()` commits the prefix that agrees with the previous hypothesis and
|
|
185
|
+
retains the unmatched tail for the next comparison. The progress marker is
|
|
186
|
+
`last_commited_time` (one `t` in the source); there is no `committed_upto`.
|
|
187
|
+
|
|
188
|
+
**Trimming.** `buffer_trimming=("segment", seconds)`: once the buffer exceeds the
|
|
189
|
+
threshold, cut at a completed Whisper segment inside committed audio.
|
|
190
|
+
`("sentence", seconds)`: cut at the second-last completed sentence, falling back to
|
|
191
|
+
the segment rule past 30 s. `chunk_at()` drops committed hypothesis entries,
|
|
192
|
+
slices the audio buffer at the sample boundary, and advances
|
|
193
|
+
`buffer_time_offset`. Default here is `("segment", 15)`.
|
|
194
|
+
|
|
195
|
+
**Prompt.** `init_prompt` is up to 200 characters of the most recent committed
|
|
196
|
+
text that has already scrolled out of the buffer. Committed text still inside the
|
|
197
|
+
buffer is returned separately for logging and is not prompted.
|
|
198
|
+
|
|
199
|
+
**`finish()` does not transcribe.** Verified at
|
|
200
|
+
`vcbot/vendor/whisper_streaming/whisper_online.py:682`: it flushes the uncommitted
|
|
201
|
+
hypothesis (`transcript_buffer.complete()`), clears the buffer, and returns the
|
|
202
|
+
same tuple shape as `process_iter()`. Ending an utterance is therefore cheap — the
|
|
203
|
+
expensive part is the periodic `process_iter()` pass over the whole buffer.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Local sources of truth
|
|
208
|
+
|
|
209
|
+
| what | where |
|
|
210
|
+
| --- | --- |
|
|
211
|
+
| receive/decode path, RTP layout | `vcbot/transcription.py:541-604` |
|
|
212
|
+
| listener registration, keepalive | `vcbot/transcription.py:532`, `:617` |
|
|
213
|
+
| DAVE session usage | `vcbot/transcription.py:582-586` |
|
|
214
|
+
| model loading, thread budget, streaming override | `vcbot/whisper_backend.py` |
|
|
215
|
+
| vendored streaming ASR | `vcbot/vendor/whisper_streaming/whisper_online.py` |
|
|
216
|
+
| upstream package signatures | `.venv/bin/python -c "import inspect, davey; ..."` |
|
vcbot-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Development and release tasks for vcbot.
|
|
2
|
+
#
|
|
3
|
+
# `uv` is only needed to create the environment and to build; once the project
|
|
4
|
+
# is installed the console script and the tests run from .venv directly.
|
|
5
|
+
|
|
6
|
+
PYTHON ?= .venv/bin/python
|
|
7
|
+
UV ?= uv
|
|
8
|
+
PYVER ?= 3.13
|
|
9
|
+
|
|
10
|
+
.DEFAULT_GOAL := help
|
|
11
|
+
.PHONY: help venv install install-cuda test lint format build legacy check clean
|
|
12
|
+
|
|
13
|
+
help: ## Show the available targets
|
|
14
|
+
@grep -hE '^[a-z-]+:.*## ' $(MAKEFILE_LIST) | sed 's/:.*## /\t/'
|
|
15
|
+
|
|
16
|
+
venv: ## Create .venv if it does not exist yet
|
|
17
|
+
@test -x $(PYTHON) || $(UV) venv .venv --python $(PYVER)
|
|
18
|
+
|
|
19
|
+
install: venv ## Editable install with build and lint tools
|
|
20
|
+
$(UV) pip install --python $(PYTHON) -e ".[dev]"
|
|
21
|
+
|
|
22
|
+
install-cuda: venv ## Editable install including the CUDA wheel set
|
|
23
|
+
$(UV) pip install --python $(PYTHON) -e ".[dev,cuda]"
|
|
24
|
+
|
|
25
|
+
test: install ## Run the test suite
|
|
26
|
+
$(PYTHON) -m unittest vcbot.test_transcription
|
|
27
|
+
|
|
28
|
+
lint: install ## Check formatting and lint rules
|
|
29
|
+
$(PYTHON) -m ruff check vcbot setup.py
|
|
30
|
+
|
|
31
|
+
format: install ## Apply the lint fixes that are safe
|
|
32
|
+
$(PYTHON) -m ruff check --fix vcbot setup.py
|
|
33
|
+
|
|
34
|
+
build: clean ## Build the sdist and wheel into dist/
|
|
35
|
+
$(UV) build
|
|
36
|
+
|
|
37
|
+
legacy: install ## Verify setup.py reports the same name and version as pyproject.toml
|
|
38
|
+
@test "$$($(PYTHON) setup.py --version 2>/dev/null)" = "$$($(PYTHON) -c 'import vcbot; print(vcbot.__version__)')" \
|
|
39
|
+
&& echo "setup.py version: $$($(PYTHON) setup.py --version 2>/dev/null)"
|
|
40
|
+
@test "$$($(PYTHON) setup.py --name 2>/dev/null)" = "vcbot" \
|
|
41
|
+
&& echo "setup.py name: $$($(PYTHON) setup.py --name 2>/dev/null)"
|
|
42
|
+
|
|
43
|
+
check: build legacy ## Install the wheel in a scratch environment and run the entry point
|
|
44
|
+
$(UV) venv .build-venv --python $(PYVER)
|
|
45
|
+
$(UV) pip install --python .build-venv/bin/python --no-deps dist/*.whl
|
|
46
|
+
.build-venv/bin/vcbot --version
|
|
47
|
+
.build-venv/bin/vcbot --help > /dev/null
|
|
48
|
+
rm -rf .build-venv
|
|
49
|
+
|
|
50
|
+
clean: ## Remove build artefacts and caches
|
|
51
|
+
rm -rf dist build .ruff_cache .build-venv *.egg-info
|
|
52
|
+
find . -path ./.venv -prune -o -name __pycache__ -type d -prune -exec rm -rf {} +
|
vcbot-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vcbot
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Discord voice selfbot with local Whisper streaming transcription and TTS playback.
|
|
5
|
+
Keywords: discord,selfbot,transcription,tts,voice,whisper
|
|
6
|
+
Classifier: Development Status :: 4 - Beta
|
|
7
|
+
Classifier: Environment :: Console
|
|
8
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
9
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Requires-Dist: audioop-lts>=0.2.2; python_version >= '3.13'
|
|
18
|
+
Requires-Dist: ctranslate2<5,>=4.5
|
|
19
|
+
Requires-Dist: davey==0.1.0
|
|
20
|
+
Requires-Dist: discord-py-self[voice]==2.1.0
|
|
21
|
+
Requires-Dist: faster-whisper==1.2.1
|
|
22
|
+
Requires-Dist: librosa
|
|
23
|
+
Requires-Dist: numpy>=1.26
|
|
24
|
+
Requires-Dist: pynacl<1.6,>=1.5
|
|
25
|
+
Requires-Dist: scipy
|
|
26
|
+
Requires-Dist: soundfile
|
|
27
|
+
Requires-Dist: yt-dlp
|
|
28
|
+
Provides-Extra: cuda
|
|
29
|
+
Requires-Dist: cuda-bindings<14,>=12.8; extra == 'cuda'
|
|
30
|
+
Requires-Dist: nvidia-cublas-cu12; extra == 'cuda'
|
|
31
|
+
Requires-Dist: nvidia-cudnn-cu12; extra == 'cuda'
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
34
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
35
|
+
Requires-Dist: setuptools>=68; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# Discord voice selfbot
|
|
39
|
+
|
|
40
|
+
Play local audio, YouTube, or SoundCloud in a voice call, speak text with
|
|
41
|
+
eSpeak, and record and transcribe other participants locally with WhisperStreaming.
|
|
42
|
+
|
|
43
|
+
## Setup
|
|
44
|
+
|
|
45
|
+
Use Python 3.11 or newer. Install FFmpeg for
|
|
46
|
+
link playback and other audio formats, eSpeak NG (or eSpeak) for `>tts`, and
|
|
47
|
+
the Opus shared library for voice. On Debian or Ubuntu:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
sudo apt install ffmpeg espeak-ng libopus0 python3-venv
|
|
51
|
+
python3 -m venv .venv
|
|
52
|
+
make install # or: .venv/bin/pip install -e ".[dev]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`make install` creates the virtualenv if needed and installs the project in
|
|
56
|
+
editable mode, which also puts the `vcbot` command on the environment's `PATH`.
|
|
57
|
+
|
|
58
|
+
CPU transcription needs no CUDA libraries. For NVIDIA GPU transcription,
|
|
59
|
+
install CUDA 12 cuBLAS and cuDNN 9. On Linux or WSL, the bot loads them
|
|
60
|
+
from the system or from NVIDIA's wheels installed in the same Python
|
|
61
|
+
environment:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
make install-cuda # or: .venv/bin/pip install -e ".[cuda]"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
On Windows, make the CUDA and cuDNN DLLs available on `PATH`.
|
|
68
|
+
|
|
69
|
+
Set `DISCORD_USER_TOKEN` in the environment and run `vcbot`. From a checkout that
|
|
70
|
+
is not installed, `python -m vcbot` is equivalent.
|
|
71
|
+
Keep the token out of source files and shell history. This program signs in
|
|
72
|
+
as a user account; Discord prohibits selfbots on its platform.
|
|
73
|
+
|
|
74
|
+
## Startup options
|
|
75
|
+
|
|
76
|
+
Run `vcbot --help` to see every option. Flags override environment
|
|
77
|
+
variables, which override built-in defaults. Leave the token in
|
|
78
|
+
`DISCORD_USER_TOKEN` when possible; a token passed as `--discord-user-token`
|
|
79
|
+
(`--token`) can appear in shell history and in the process list.
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
vcbot --whisper-backend cpu --whisper-model base --whisper-streams 1
|
|
83
|
+
vcbot --prefix '!' --reply-delete-after 30 --recordings-dir ./voice-logs --debug
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
| Flag | Environment variable | Default |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `--discord-user-token` | `DISCORD_USER_TOKEN` | Required |
|
|
89
|
+
| `--prefix` | `SELFBOT_PREFIX` | `>` |
|
|
90
|
+
| `--reply-delete-after` | `SELFBOT_REPLY_DELETE_AFTER` | 20 seconds |
|
|
91
|
+
| `--voice-timeout` | `SELFBOT_VOICE_TIMEOUT` | 20 seconds |
|
|
92
|
+
| `--tts-voice` | `SELFBOT_TTS_VOICE` | `en-us+whisper` |
|
|
93
|
+
| `--tts-speed`, `--tts-pitch`, `--tts-amplitude` | `SELFBOT_TTS_SPEED`, `SELFBOT_TTS_PITCH`, `SELFBOT_TTS_AMPLITUDE` | eSpeak defaults; each `>tts` call can override them |
|
|
94
|
+
| `--recordings-dir` | `SELFBOT_RECORDINGS_DIR` | `./recordings` |
|
|
95
|
+
| `--whisper-model` | `WHISPER_MODEL` | `turbo` |
|
|
96
|
+
| `--whisper-language` (`--whisper-lang`) | `WHISPER_LANGUAGE` | `en`; `auto` detects the language on every chunk |
|
|
97
|
+
| `--whisper-vad` / `--no-whisper-vad` | `WHISPER_VAD=1` | Off; runs Silero VAD on each chunk to drop non-speech |
|
|
98
|
+
| `--whisper-backend` (`--whisper-device`) | `WHISPER_BACKEND` | `auto` (CUDA if visible, otherwise CPU); also accepts `cpu` and `cuda` |
|
|
99
|
+
| `--whisper-streams` | `WHISPER_STREAMS` | 2 on CPU or 4 on CUDA |
|
|
100
|
+
| `--whisper-workers` | `WHISPER_WORKERS` | Available logical CPUs, capped at 32 by default |
|
|
101
|
+
| `--whisper-vram-percent` | `WHISPER_VRAM_PERCENT` | 75% (CUDA only) |
|
|
102
|
+
| `--whisper-chunk-seconds` | `WHISPER_CHUNK_SECONDS` | 2 seconds (1–10) |
|
|
103
|
+
| `--whisper-pause-seconds` | `WHISPER_PAUSE_SECONDS` | 1 second |
|
|
104
|
+
| `--debug` / `--no-debug` | `SELFBOT_DEBUG=1` | Off |
|
|
105
|
+
|
|
106
|
+
## Commands
|
|
107
|
+
|
|
108
|
+
Type these as regular messages. Replies, including help and transcript
|
|
109
|
+
attachments, are visible in the conversation before being deleted after
|
|
110
|
+
about 20 seconds. Only the signed-in account can run commands directly;
|
|
111
|
+
other users can invoke `@mention >tts ...`.
|
|
112
|
+
|
|
113
|
+
| Command | What it does |
|
|
114
|
+
| --- | --- |
|
|
115
|
+
| `>help`, `>ping` | Show command help or gateway latency. |
|
|
116
|
+
| `>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. |
|
|
117
|
+
| `>vc_active` | Show which voice session this conversation controls, including connection, playback, and recording status. |
|
|
118
|
+
| `>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. |
|
|
119
|
+
| `>diagnostics` | Check gateway and voice connectivity, local tools, and recording packet and queue counts. |
|
|
120
|
+
| `>tts [options] <text>` | Speak text in the active call. |
|
|
121
|
+
| `>voices [query]` | List or filter installed voices and variants. |
|
|
122
|
+
| `>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. |
|
|
123
|
+
| `>pause`, `>resume`, `>skip` | Control active playback. Recording continues independently. |
|
|
124
|
+
| `>models` | List the model names accepted by `>record`, including models that download on first use. |
|
|
125
|
+
| `>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. |
|
|
126
|
+
| `>log <n>` | Show the last `n` lines of the current or latest transcript. Long results are sent as an attachment. |
|
|
127
|
+
| `>stop` | Finish writing the recording and transcript without leaving voice. |
|
|
128
|
+
| `>leave` | Disconnect and finish any active recording. |
|
|
129
|
+
|
|
130
|
+
In a server, try `>join General Voice` or pass a channel mention or ID. With
|
|
131
|
+
no argument, `>join` uses the voice channel whose chat you are typing in
|
|
132
|
+
or the channel the signed-in account is currently in. To join from another
|
|
133
|
+
server or a private conversation, send `>join <server_id> <channel_id>` or
|
|
134
|
+
`>join https://discord.com/channels/<server_id>/<channel_id>`. The signed-in
|
|
135
|
+
account needs access to that channel. After a remote join, you can run voice
|
|
136
|
+
commands in the conversation that started the join or in the destination
|
|
137
|
+
server. Replies (including `>vc_list` and `>log`) appear where you run the
|
|
138
|
+
command. Run `>join` for a local channel or call to switch that conversation
|
|
139
|
+
back to local controls.
|
|
140
|
+
|
|
141
|
+
TTS options go before the text: `--voice` (`-v`, default `en-us+whisper`),
|
|
142
|
+
`--speed` (`-s`, 80–450 words per minute), `--pitch` (`-p`, 0–99), and
|
|
143
|
+
`--amplitude` (`-a`, 0–200). Example: `>tts --voice fr --speed 140 Bonjour`.
|
|
144
|
+
Loud playback and TTS leave 6 dB of peak headroom before Opus encoding.
|
|
145
|
+
Recording also leaves 6 dB of headroom inside the Opus decoder before saving
|
|
146
|
+
16-bit WAV files.
|
|
147
|
+
|
|
148
|
+
## Troubleshooting
|
|
149
|
+
|
|
150
|
+
- Run `>ping` to verify commands are reaching the bot. Run `>vc_active` to see
|
|
151
|
+
where voice commands will go. If Discord shows you in voice but the bot has
|
|
152
|
+
no connection, run `>join` to establish its audio session.
|
|
153
|
+
- Run `>diagnostics` while recording to see whether voice packets arrive and
|
|
154
|
+
decode. The decoded count excludes Discord's silence packets; a low count
|
|
155
|
+
while nobody is speaking is normal. Opus may report "not loaded yet" before
|
|
156
|
+
the first use.
|
|
157
|
+
- Start with `vcbot --debug` for command, voice, playback,
|
|
158
|
+
and recording logs in the terminal.
|
|
159
|
+
|
|
160
|
+
## Recording
|
|
161
|
+
|
|
162
|
+
WhisperStreaming runs a separate online processor for each speaker. During
|
|
163
|
+
continuous speech it receives audio about every two seconds by default, confirms words
|
|
164
|
+
that agree across successive passes, and trims completed segments to keep the
|
|
165
|
+
working audio window short. A pause, speaker disconnect, or recording stop
|
|
166
|
+
flushes any remaining words. WhisperStreaming uses faster-whisper and
|
|
167
|
+
CTranslate2 as its local inference engine on CPU and CUDA.
|
|
168
|
+
|
|
169
|
+
Use `>record base` for a lighter model, especially on CPU. Model selection
|
|
170
|
+
follows the command argument, then the configured default (`turbo`). The
|
|
171
|
+
first use of a model may download its CTranslate2 weights from Hugging Face;
|
|
172
|
+
previous OpenAI Whisper `.pt` files are not used. `WHISPER_STREAMS` caps the
|
|
173
|
+
total number of loaded or loading Whisper instances across all calls and
|
|
174
|
+
model names in the process. The default is 2 on CPU or 4 on CUDA. Set it
|
|
175
|
+
to 1 if RAM or VRAM is limited. Idle instances are reused or evicted if
|
|
176
|
+
another model needs their slot.
|
|
177
|
+
|
|
178
|
+
Whisper detects the spoken language separately on every chunk unless one is
|
|
179
|
+
given. Set `--whisper-language es` (or `WHISPER_LANGUAGE`) to make that the
|
|
180
|
+
default for every recording, or pass `>record --language es` to override it
|
|
181
|
+
for one session. Use `auto` to keep detecting. Fixing the language removes
|
|
182
|
+
the detection pass from each inference, and `>vc_active` and
|
|
183
|
+
`>diagnostics` show the language in use. English-only models (`base.en` and
|
|
184
|
+
similar) only accept `en` (or `auto`, which still transcribes as English).
|
|
185
|
+
|
|
186
|
+
Voice activity detection is off by default. Set `--whisper-vad` (or
|
|
187
|
+
`WHISPER_VAD=1`) to run faster-whisper's bundled Silero VAD over each chunk
|
|
188
|
+
and drop non-speech before transcription, which avoids hallucinated lines on
|
|
189
|
+
music, noise, or silence. Pass `>record --vad` or `>record --no-vad` to
|
|
190
|
+
override it for one session. This is the vendored `--vad` option; the
|
|
191
|
+
vendored `--vac` option is not ported because it expects 40 ms chunks and
|
|
192
|
+
downloads a Torch model, while this bot already splits audio per speaker and
|
|
193
|
+
flushes on pauses. VAD state appears in `>vc_active` and `>diagnostics`.
|
|
194
|
+
|
|
195
|
+
The transcription worker pool is sized separately, using the logical CPUs
|
|
196
|
+
available to the process (at least 1 and at most 32). On CUDA, model
|
|
197
|
+
admission also targets 75% of total GPU memory by default. Set
|
|
198
|
+
`WHISPER_VRAM_PERCENT` to a whole number from 1 to 100 to change that target.
|
|
199
|
+
The check accounts for other GPU usage and reserves an estimated inference
|
|
200
|
+
footprint for each Whisper instance, including loads in progress. The
|
|
201
|
+
effective instance limit can therefore be lower than `WHISPER_STREAMS`.
|
|
202
|
+
The budget is an estimate: inference peaks and memory changes in other
|
|
203
|
+
processes can still cause higher usage. It does not apply to CPU recording.
|
|
204
|
+
|
|
205
|
+
Each session writes `<session>/transcript.txt` under the recordings directory and
|
|
206
|
+
`<user_id>.wav` tracks in the same directory. The WAVs contain captured
|
|
207
|
+
speech chunks at 48 kHz stereo; they omit gaps with no received audio.
|
|
208
|
+
Silence, near-silence, and brief spikes are skipped before Whisper
|
|
209
|
+
inference; captured audio is still saved to the WAV tracks. Processed
|
|
210
|
+
lines appear in the terminal as well as the transcript. Each call can queue
|
|
211
|
+
up to 32 audio chunks or 60 seconds of audio, whichever fills first. Under
|
|
212
|
+
sustained load, the recorder continues saving WAVs and skips new transcription
|
|
213
|
+
work when the queue is full. `>diagnostics` shows the skipped audio duration.
|
|
214
|
+
`>stop` waits for queued transcription to finish. Record only with
|
|
215
|
+
participants' knowledge and permission.
|
|
216
|
+
|
|
217
|
+
## Packaging
|
|
218
|
+
|
|
219
|
+
The project is a PEP 517 package built with hatchling, so `pip install .` and
|
|
220
|
+
`uv build` both work. `vcbot` is a console script (`vcbot = "vcbot.cli:main"`)
|
|
221
|
+
and `python -m vcbot` runs the same entry point; the version lives in
|
|
222
|
+
`vcbot/__init__.py`.
|
|
223
|
+
|
|
224
|
+
```sh
|
|
225
|
+
make build # dist/vcbot-<version>.tar.gz and dist/vcbot-<version>-py3-none-any.whl
|
|
226
|
+
make check # build, install the wheel in a scratch venv, run --version and --help
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`make test` runs the unit tests with `unittest`; `make lint` runs ruff over the
|
|
230
|
+
package, with the vendored WhisperStreaming code excluded.
|
|
231
|
+
|
|
232
|
+
`setup.py` is a shim for tooling that still expects one: it reads every field
|
|
233
|
+
back out of `pyproject.toml` at build time, so it cannot drift. `pyproject.toml`
|
|
234
|
+
remains authoritative and hatchling remains the build backend.
|
|
235
|
+
|
|
236
|
+
### Continuous integration
|
|
237
|
+
|
|
238
|
+
`.github/workflows/ci.yml` runs on every push to `master` and on pull requests:
|
|
239
|
+
|
|
240
|
+
- **lint** — ruff over `vcbot/` and `setup.py`.
|
|
241
|
+
- **test** — the unit tests, the console script and `python -m vcbot` on Python
|
|
242
|
+
3.11, 3.12 and 3.13.
|
|
243
|
+
- **package** — builds the sdist and wheel, installs each into a throwaway
|
|
244
|
+
environment, then checks the wheel layout (no tests, vendored `LICENSE`
|
|
245
|
+
present, `vcbot = vcbot.cli:main`) and that `setup.py` reports the same name
|
|
246
|
+
and version as the package.
|
|
247
|
+
|
|
248
|
+
Pushing a `v*` tag runs `.github/workflows/release.yml`, which refuses to
|
|
249
|
+
publish unless the tag matches `vcbot/__init__.py`, then attaches the built
|
|
250
|
+
artefacts to a GitHub release.
|
|
251
|
+
|
|
252
|
+
## Code layout
|
|
253
|
+
|
|
254
|
+
Everything below lives in the `vcbot/` package.
|
|
255
|
+
|
|
256
|
+
- `cli.py` parses the command line and then imports the application, so
|
|
257
|
+
`--help` and argument errors never load Discord or Whisper.
|
|
258
|
+
- `config.py` defines startup options, environment fallbacks, and defaults.
|
|
259
|
+
- `main.py` registers commands, handles voice connections and playback
|
|
260
|
+
reservations, and sets the reply deletion timer.
|
|
261
|
+
- `speech.py` prepares audio from eSpeak, local files, or yt-dlp links.
|
|
262
|
+
- `transcription.py` receives Discord voice packets, segments audio, and
|
|
263
|
+
writes WAVs and transcripts using bounded Whisper concurrency. While
|
|
264
|
+
recording, it keeps the voice UDP socket active through quiet periods.
|
|
265
|
+
- `whisper_backend.py` connects WhisperStreaming processors to the shared
|
|
266
|
+
model pool and checks CUDA VRAM.
|
|
267
|
+
- `vendor/whisper_streaming/` contains the online WhisperStreaming module and license
|
|
268
|
+
derived from [WhisperStreaming revision `6da90b4`](https://github.com/ufal/whisper_streaming/tree/6da90b44b7e50d79695e68166d2a2c7609c75abb).
|