2026/08/06Hey, are you Earthlings having trouble with Earth-speak?
17:46
Good evening, Kappa-dappa!(o’Θ’o)ノ))
Um… I said, “It’s Kappa!”ヾ(・Θ・` )
Anyway, listen—in games like Survival and PvP games, I keep running into Earthlings who say stuff I don’t understand!
I’m not good at either Japanese or Earth languages, so it’s always a hassle! ┐(゜Θ。)┌ Oh well…
So, I recently set things up so I can translate Earth languages other than Japanese into Japanese—without using my home computer—and display them on screen via OBS or text!
I was so happy, thinking, “Now I can watch foreign shows without subtitles with peace of mind!”
But…
My original goal was to have it recognize the words I spoke as Japanese and translate them into other languages…
While it’s 80–90% accurate with English and standard Japanese speech, it stops working completely when I use it on my own voice!
Darn it! It’s Earth’s AI and speech recognition! Kappa wasn’t included in the system after all! XDD
So, that left me feeling pretty down.
Well, never mind that.
You guys still play games and browse all kinds of media, right?
You don’t play for 8 hours a day, do you?
You don’t use up all the free tokens on that service called Cloudflare, do you?
You’re not such a chatterbox that you talk nonstop for 6 hours a day, are you?
OK!
In that case, why not try using this to decipher random comments from people outside the English-speaking world?
Hopefully, you don’t live in the Tower of Babel.
This is Kappa!
Below is an explanation from the AI you’ve all been trusting lately!
Just so you know, I’m not responsible if you use this—even if it blows up or humanity goes extinct, it’s not my fault.
OBS + Cloudflare Workers AI + AI Gateway Subtitle Script v6.3 (0805)
Real-time subtitle translation script for OBS streaming. Combines Cloudflare Workers AI (Whisper speech recognition + LLM translation) with AI Gateway for low-latency, low-cost subtitle generation. Runs entirely on the Cloudflare Workers AI free tier (10,000 Neurons/day).
Table of Contents
- Features
- Requirements
- Cloudflare Account Setup
- Running the Script
- OBS Configuration
- Use Cases
- Whisper Model Selection
- Troubleshooting
- Version History
- License
- Disclaimer
- Differences from the Japanese Version
Features
Speech Recognition & Translation
| Feature | Description |
|---|---|
| Whisper speech recognition | Uses @cf/openai/whisper (multilingual), @cf/openai/whisper-tiny-en (English-only, fast), or @cf/openai/whisper-large-v3-turbo (high-accuracy) on Cloudflare Workers AI |
| LLM translation | Translates via @cf/meta/llama-3.1-8b-instruct-fast. Supports Japanese to English, English to Japanese, bidirectional auto-detect |
| AI Gateway routing | All API requests go through AI Gateway for caching, logging, and rate limiting |
| Prompt Caching | x-session-affinity header caches common prefix for reduced TTFT + Neuron savings (v6.2+) |
| Token usage display | [Token] in=X out=Y shows real-time Neuron consumption (v6.2+) |
Noise Removal & VAD
| Feature | Description |
|---|---|
| Dynamic noise gate | Learns ambient noise for 30 seconds at startup, auto-sets noise floor (mic mode only) |
| Frequency VAD | Judges human voice by 200-3400Hz band power. Filters BGM/SFX |
| Pre-FFT energy check | Skips FFT for low-energy chunks (CPU savings). Threshold tuned to 3.0 (v6.2+) |
| Silence trimming | Cuts leading/trailing silence to reduce API payload |
| Audio normalization | DC offset removal + peak gain adjustment |
Hallucination Detection
| Feature | Description |
|---|---|
| Short text skip | Skips 1-word hallucinations <=3 chars |
| Repetition detection | Trims when same 3-char phrase repeats 8+ times |
| Prompt leak detection | Detects prompt leaks, skips |
Note: Language-specific filters (Hangul, Cyrillic, Greek, Thai, Chinese, European languages, Nordic, Special Latin) are intentionally removed in the English version. English-version users may want to transcribe/translate those languages, so filtering them out would drop valid transcriptions. Only generic hallucination detection (short text, repetition, prompt leak) remains.
Filters & Quality Control
| Feature | Description |
|---|---|
| NG word filter | 200+ NG words pre-compiled as regex. Word boundary \b and substring match variants |
| Duplicate skip | Skips if >=85% similar to previous transcription |
| Translation loop detection | Trims when same phrase repeats in translation output |
| Translation safety refusal detection | Detects “I cannot provide” etc., uses original text |
| Translation failure detection | Detects Japanese returned as-is in ja_to_en, uses original text |
Note on NG words: The NG word list includes 200+ words, many of which are Japanese-specific. If you are an English speaker using Guardrails ON (recommended), Cloudflare’s native content moderation will handle filtering – the built-in NG word list will have no visible effect on your transcription. If you use Guardrails OFF, the NG word list will still mask matching words, but most Japanese-specific entries will not match English speech. You can safely ignore the NG word list or customize
NG_WORDSandNG_WORDS_BOUNDEDin the script for your own language.
Recording & Pipeline
| Feature | Description |
|---|---|
| InputStream continuous recording | PortAudio callback for gapless recording |
| Ring buffer | deque(maxlen=...) auto-discards old data on overrun |
| Non-blocking pipeline | Separate recording thread and API worker thread |
| HTTP session reuse | TCP/TLS handshake only once. Saves 100-300ms per cycle |
| Atomic write | Temp file then os.replace() prevents OBS read corruption |
| API retry | Both Whisper and translation API retry up to 2 times |
| Guardrails handling | Detects AI Gateway Guardrails blocks (code 2016/2017), skips |
Modes & Settings
| Feature | Description |
|---|---|
| Microphone mode | Picks up your voice. Dynamic noise gate enabled |
| Stream mode | Picks up game/stream audio. Higher VAD threshold |
| Bidirectional auto-detect | Auto-detects Japanese/English, decides translation direction. [JA]/[EN] tags |
| English-only mode | Picks up English only, passes through Japanese |
| Non-Japanese all mode | Picks up all non-Japanese audio, translates to Japanese |
| Latency modes | Choose 3s (low) / 5s (normal) / 8s (accuracy) |
| Genre hints | Game/chat/tech/music/kappa vocabulary hints for Whisper |
| Whisper model selection | Choose standard or high-accuracy model at startup (v6.2+) |
| 15s auto-clear | Auto-clears subtitle after 15 seconds of silence |
| Environment variable | API token via CF_API_TOKEN environment variable |
Requirements
- Python 3.10+
- pip packages:
sounddevice,requests,numpy,scipy - Cloudflare account (Free tier OK)
- OBS Studio (Text Source (GDI+) required)
pip install
pip install sounddevice requests numpy scipy
scipyis optional but recommended for higher-quality resampling.
Cloudflare Account Setup
Step 1: Create a Cloudflare Account
- Sign up at Cloudflare
- Log in to the Cloudflare Dashboard
Step 2: Get Your Account ID
- Select your account in the dashboard sidebar
- Copy the Account ID (32-character alphanumeric)
- Set it in the script as
ACCOUNT_ID
Step 3: Create an API Token
- Go to API Tokens
- Click Create Token
- Select Create Custom Token
- Set the following permissions:
- Account > Workers AI – Read
- Account > AI Gateway – Read, Edit
- Continue to summary then Create Token
- Copy the token (shown only once)
Step 4: Create an AI Gateway
- Go to AI Gateway
- Click Create Gateway
- Enter a name (e.g.,
default) - Click Create
Auto-creation: Specifying
defaultas the Gateway ID in API requests will auto-create the gateway on first request.
Guardrails: ON or OFF?
| Audience | Guardrails | NG word list | Reason |
|---|---|---|---|
| English speakers | ON (recommended) | Not needed | Cloudflare’s native content moderation is high-accuracy for English. Simplest setup. |
| Japanese speakers | OFF (recommended) | Custom 200+ words | Neuron savings. Japanese NG expressions covered by custom filter. |
Step 5: Enable AI Gateway Cache (Required – no Neuron savings without it)
- Go to AI Gateway and select your gateway
- Open Settings
- Turn Cache Responses ON
- Set default cache TTL to 300 seconds
Without this ON, caching won’t work. It won’t error, but Neuron savings will be zero. Make sure to turn it ON.
AI Gateway is completely free. Cache and logging features are free with no additional charges.
The script also specifies cache TTL via the cf-aig-cache-ttl header (TRANSLATE_CACHE_TTL = 300).
Step 6: Set Credentials in the Script
Using environment variables (recommended):
# Windows (Command Prompt)
set CF_API_TOKEN=your_token
# Windows (PowerShell)
$env:CF_API_TOKEN = "your_token"
# Mac / Linux
export CF_API_TOKEN=your_token
Or write directly into the script:
CLOUDFLARE_API_TOKEN = os.environ.get("CF_API_TOKEN", "cfat_paste_your_token_here")
Also set ACCOUNT_ID and GATEWAY_ID:
ACCOUNT_ID = "your_account_id"
GATEWAY_ID = "default" # Gateway name you created
Step 7: Verify Workers AI Access
- Go to Workers AI
- Confirm the model list is displayed
- Check Usage tab for Neuron consumption
Pricing (Don’t Worry)
| Item | Cost |
|---|---|
| AI Gateway creation & usage | Free |
| AI Gateway cache feature | Free |
| AI Gateway logging | Free |
| Additional subscription | Not required |
Workers AI (Whisper + LLM translation) pricing:
| Plan | Free tier | Over limit | Auto-billing |
|---|---|---|---|
| Free (current) | 10,000 Neurons/day free | Errors and stops | No |
| Paid ($5/mo) | 10,000 Neurons/day free | $0.011 / 1,000 Neurons | Yes |
You can use the Free plan. Up to 10,000 Neurons per day is free. No auto-billing on overage. It just errors and stops. Billing requires intentionally upgrading to Workers Paid ($5/mo).
Running the Script
python obs_subtitle_translator_0805_v6_3_en.py
At startup, you’ll be prompted to select:
- Mode: Microphone (1) or Stream (2)
- Language: Translation direction (1-5)
- Device: Default (d) or list (l) or device number
- Genre: Game/chat/tech/music/none/kappa (1-6)
- Latency: Low (3s) / Normal (5s) / Accuracy (8s)
- Whisper model: Standard (1) or High-accuracy (2)
Device Number Warning: The default device numbers (
DEFAULT_MIC_DEVICE = 7,DEFAULT_GAME_DEVICE = 61) are specific to the author’s machine. Your device numbers will be different. Always enterlat the device selection prompt to list available devices and pick the correct one for your system.
OBS Configuration
- Open OBS Studio
- Sources then + then Text (GDI+)
- Open the text source properties
- Check Read from file
- Browse and select
output_mic.txtoroutput_game.txt - Set Encoding to UTF-8
- Adjust font, size, and color
Subtitles update automatically. After 15 seconds of silence, the subtitle is cleared.
Mic Mode Usage Notes
- Stay silent for the first ~30 seconds after startup (noise floor learning in progress)
- Do not touch the mic during learning (noise floor will spike)
- Once
[Noise Gate Confirmed]log appears, learning is done – OK to speak - Learning with the same environment as streaming (with BGM) is recommended
- Press
Ctrl+Cto exit (output file will be cleared)
Use Cases
Example 1: Japanese Streamer to English Subtitles
Mode: 1 (Microphone) Language: 1 (Japanese to English) Latency: 2 (Normal 5s)
Example 2: English Game Stream to Japanese Subtitles
Mode: 2 (Stream) Language: 1 (English to Japanese) Latency: 3 (Accuracy 8s)
Example 3: Bidirectional Auto-Detect (Mixed JP/EN Stream)
Mode: 1 (Microphone) Language: 3 (Auto-detect) Latency: 2 (Normal 5s)
Example 4: English-Only Mode (Japanese Pass-Through)
Mode: 2 (Stream) Language: 4 (English only, Japanese pass-through)
Example 5: Kappa Streaming (Vocabulary Hint)
“Kappa streaming” is a Japanese VTuber/streamer style where the streamer uses sentences ending with “-ppa” (a verbal tic). Genre 6 adds these patterns as Whisper vocabulary hints for better recognition. Non-Japanese speakers can ignore this option.
Mode: 1 (Microphone) Language: 1 (Japanese to English) Genre: 6 (Kappa)
Example 6: Tech Streaming (Technical Terms)
Mode: 1 (Microphone) Language: 1 (Japanese to English) Genre: 3 (Tech/Programming)
Example 7: Low Latency Mode
Mode: 1 (Microphone) Language: 1 (Japanese to English) Latency: 1 (Low 3s)
Example 8: Accuracy Priority for Noisy Environments
Mode: 2 (Stream) Language: 1 (English to Japanese) Latency: 3 (Accuracy 8s)
Example 9: High-Accuracy Whisper Model
Mode: 1 (Microphone) Language: 1 (Japanese to English) Whisper model: 2 (High-accuracy)
Example 10: French Stream to English Subtitles
Mode: 1 (Microphone) Language: 2 (Speak English to Japanese) Genre: 5 (None)
For French to English, use Whisper auto-detect mode (
whisper_language = "auto") by modifying the script. The translation prompt can be changed to “Translate the following French to English” for best results.
Example 11: Korean Stream to English Subtitles
Mode: 1 (Microphone) Language: 2 (Speak English to Japanese) Genre: 5 (None)
Same as above – use Whisper auto-detect and modify the translation prompt. Language-specific hallucination filters are removed in the English version, so Korean speech will be transcribed correctly.
Example 12: Spanish Game Stream to English Subtitles
Mode: 2 (Stream) Language: 1 (English to Japanese) Genre: 5 (None) Latency: 3 (Accuracy 8s)
For Spanish to English, use Whisper auto-detect and modify the translation direction. European language hallucination filters are removed in the English version, so Spanish speech will be transcribed correctly.
Whisper Model Selection
| Model | Neurons/min | Accuracy | Free tier usage (approx.) |
|---|---|---|---|
| Standard (@cf/openai/whisper) | 41.14 | Medium | ~8 hours |
| High-accuracy (whisper-large-v3-turbo) | 46.63 | High | ~7 hours |
Free tier is 10,000 Neurons/day. Streaming (with conversation gaps) gives 6-11 hours of usage. The high-accuracy model does not support
temperature/promptparameters and sends audio as base64 JSON.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Not picking up voice | VAD precheck threshold too high | Lower VAD_PRECHECK_THRESHOLD from 3.0 to 2.0 |
| Picking up too much noise | VAD precheck threshold too low | Raise VAD_PRECHECK_THRESHOLD from 3.0 to 5.0 |
| Not picking up game audio | VAD threshold too high | Lower VAD_THRESHOLD_GAME from 400 to 300 |
| Picking up too much game audio | VAD threshold too low | Raise VAD_THRESHOLD_GAME from 400 to 500 |
| API error 401 | Token permissions insufficient | Verify Workers AI Read + AI Gateway Read/Edit permissions |
| API timeout | Network latency | Raise API_TIMEOUT from 30 to 60 |
| Subtitle garbled | OBS encoding | Set encoding to UTF-8 in Text Source (GDI+) |
| Nothing picked up at startup | Noise learning in progress (normal) | Wait 30 seconds. OK to speak after [Noise Gate Confirmed] |
| No [Cache Hit] shown | AI Gateway Cache Responses is OFF | Turn ON Cache Responses in dashboard, TTL 300s |
Feature List
- Whisper speech recognition (standard / high-accuracy / English-only auto-select)
- LLM translation (llama-3.1-8b-instruct-fast)
- Dynamic noise gate (mic mode)
- Frequency VAD (with pre-FFT check)
- Hallucination detection (Repetition/Short text/Prompt leak – language-specific filters removed for multilingual support)
- NG word filter (word boundary support)
- Duplicate skip / Translation loop detection / Translation safety refusal detection
- 15-second auto-clear
- AI Gateway cache (TTL 300 seconds)
- Prompt Caching (x-session-affinity)
- Token usage display (Neuron monitoring)
- Whisper API / Translation API retry (up to 2 times)
- Auto-detect mode (bidirectional translation)
License
AI Model Licenses (as of 2026/08/05)
| Model | Provider | License | Commercial Use |
|---|---|---|---|
| @cf/openai/whisper | OpenAI | MIT License | Allowed |
| @cf/openai/whisper-tiny-en | OpenAI | MIT License | Allowed |
| @cf/openai/whisper-large-v3-turbo | OpenAI | MIT License | Allowed |
| @cf/meta/llama-3.1-8b-instruct-fast | Meta | Llama Community License | Allowed (< 700M MAU) |
Note: If you switch to different models (partner models, etc.), please check their respective terms of use and licenses.
Script License
Released under the MIT License. Feel free to use, modify, and distribute.
Disclaimer
- This script is provided “AS IS”, without any warranty
- Runs on the Cloudflare Workers AI free tier (10,000 Neurons/day), but may hit the limit depending on usage
- No auto-billing on overage (it just errors and stops)
- Billing requires intentionally upgrading to Workers Paid ($5/mo)
- AI speech recognition and translation are not perfect; misrecognition may occur
- The author is not responsible for any damages arising from use during streaming
- Cloudflare service specifications, pricing, and terms of use may change. Check the Cloudflare documentation for the latest information
- AI model license conditions may change. If you modify this script to use different models, be sure to check the applicable model licenses
Version History
v6.3 (0805)
- Version bump to align with Japanese version (0805)
v6.2 (0805)
- Translation API Prompt Caching (x-session-affinity) added
- VAD_PRECHECK_THRESHOLD adjusted 50.0 to 3.0 (hallucination reduction)
- VAD_THRESHOLD_MIC adjusted 50 to 100 (faint noise rejection)
- Kappa streaming prompt enhanced (added “-ppa” conversion phrases)
- Whisper model selection added (standard / high-accuracy)
- whisper-large-v3-turbo support (base64 JSON format, temperature/prompt not supported)
- Translation API token usage display added
v6.1 (0802)
- Pre-FFT energy check (CPU load reduction)
- Auto-select English Whisper model
- Translation API AI Gateway cache
- Pre-computed frequency mask
- Shortened VAD FFT window
v6.0
- InputStream + ring buffer (continuous recording)
- Non-blocking pipeline
- Pre-compiled NG word regex
- Translation API retry / Atomic write / Environment variable support
- HTTP session reuse / Latency mode selection
- Guardrails error handling
- Dynamic noise gate learning frame count
Differences from the Japanese Version
The English version (obs_subtitle_translator_0805_v6_3_en.py) is functionally identical to the Japanese version (obs_subtitle_translator_0805_v6_3.py) except for the following changes:
Removed Features
| Feature | Japanese Version | English Version | Reason |
|---|---|---|---|
| Hangul detection | Detects Korean characters, skips | Removed | English-version users may want to transcribe Korean streams |
| Cyrillic detection | Detects Russian etc., skips | Removed | English-version users may want to transcribe Russian streams |
| Greek detection | Detects Greek, skips | Removed | English-version users may want to transcribe Greek streams |
| Thai detection | Detects Thai, skips | Removed | English-version users may want to transcribe Thai streams |
| Chinese detection | Detects simplified Chinese, skips | Removed | English-version users may want to transcribe Chinese streams |
| Special Latin detection | Detects Turkish characters, skips | Removed | English-version users may want to transcribe Turkish streams |
| Nordic detection | Detects Nordic characters, skips | Removed | English-version users may want to transcribe Nordic language streams |
| European language detection | Detects German/French/Swedish/Dutch/Spanish, skips | Removed | English-version users may want to transcribe European language streams |
| Kanji-only detection | Detects kanji-only text (<5 chars), skips | Removed | English-version users may want to transcribe kanji-only text |
Kept Features
| Feature | Status | Reason |
|---|---|---|
| Short text skip | Kept | Generic hallucination detection – not language-specific |
| Repetition detection | Kept | Generic hallucination detection – not language-specific |
| Prompt leak detection | Kept | Detects prompt leak – not language-specific |
| English hallucination skip (ja mode) | Kept | Only applies when whisper_language == "ja" – does not affect other modes |
| Translation failure detection (ja_to_en) | Kept | Only applies when direction == "ja_to_en" – does not affect other directions |
| NG word filter | Kept | All 200+ NG words kept, including Japanese NG words |
Why These Changes Were Made
The Japanese version was built for a specific use case: a Japanese-speaking streamer who primarily speaks Japanese and occasionally needs English translation. In this context, Whisper sometimes produces hallucinations – random text in Korean, Chinese, German, French, etc. – when it misinterprets silence or noise. The language-specific filters were added to catch and discard these hallucinations, since the streamer would never actually speak those languages.
However, the English version targets international users who may speak any language:
- A French streamer wanting English subtitles would have their French speech incorrectly discarded by the European language filter
- A Korean streamer wanting English subtitles would have their Korean speech incorrectly discarded by the Hangul filter
- A Russian streamer wanting English subtitles would have their Russian speech incorrectly discarded by the Cyrillic filter
- A Chinese streamer wanting English subtitles would have their Chinese speech incorrectly discarded by the Chinese filter
Removing these filters ensures that valid speech in any language is never incorrectly discarded. The trade-off is that genuine Whisper hallucinations in those languages will no longer be filtered – but this is a better experience for multilingual users than having their actual speech dropped.
The NG word filter is kept because:
- It only masks words (replaces with
***), it doesn’t discard the entire transcription - English speakers using Guardrails ON (recommended) will have Cloudflare’s native moderation handle this – the NG word list has no visible effect
- Japanese speakers using Guardrails OFF still benefit from the 200+ Japanese NG words
- Users can customize
NG_WORDSandNG_WORDS_BOUNDEDin the script for their own language
Summary
The Japanese version is optimized for Japanese streamers who primarily speak Japanese and need to filter out hallucinations in other languages. The English version is designed for international users who may transcribe and translate any language, so language-specific hallucination filters are removed to avoid dropping valid transcriptions.
コメント