Skip to content

Commit d35052a

Browse files
committed
Add audio transcription with per-chat language support
Built over a weekend to read voice messages as text instead of listening. Features: - Alt-U to transcribe voice messages - Alt-Shift-U to re-transcribe - Alt-L to set language per chat - 22+ languages (en, ru, uk, es, fr, de, zh, ja, etc.) - Auto-truncate long transcriptions (configurable max lines) - Works with OpenAI API, whisper.cpp, or local Whisper Config in ~/.config/nchat/ui.conf: - audio_transcribe_enabled=1 # turn it on - audio_transcribe_language=auto # or en, ru, uk, etc. - audio_transcribe_max_lines=15 # truncate long ones Database: Added transcriptionLanguage to chats2 table (schema v9) Docs: TRANSCRIPTION.md for usage, TRANSCRIPTION-SETUP.md for setup
1 parent fe34df8 commit d35052a

16 files changed

Lines changed: 1691 additions & 6 deletions

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ add_executable(nchat
177177
src/uilistborderview.h
178178
src/uilistdialog.cpp
179179
src/uilistdialog.h
180+
src/uilanguagelistdialog.cpp
181+
src/uilanguagelistdialog.h
180182
src/uilistview.cpp
181183
src/uilistview.h
182184
src/uimessagedialog.cpp
@@ -310,6 +312,9 @@ install(FILES src/nchat.1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
310312
configure_file(src/compose ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}/nchat/compose COPYONLY)
311313
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}/nchat/compose DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/nchat)
312314

315+
configure_file(src/transcribe ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}/nchat/transcribe COPYONLY)
316+
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}/nchat/transcribe DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/nchat)
317+
313318
# Themes
314319
macro(add_theme themedir)
315320
configure_file(themes/${themedir}/color.conf ${CMAKE_CURRENT_BINARY_DIR}/share/nchat/themes/${themedir}/color.conf COPYONLY)

doc/TRANSCRIPTION-SETUP.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# Transcription Setup
2+
3+
How to set up different transcription backends for nchat.
4+
5+
## What You Need
6+
7+
- nchat installed
8+
- Python 3.7+ (`python3 --version`)
9+
- pip (`pip3 --version`)
10+
11+
---
12+
13+
## Option 1: OpenAI API (Easiest)
14+
15+
Fast (2-3 sec), accurate, easy. Costs $0.006/min. Audio goes to OpenAI.
16+
17+
**Setup:**
18+
19+
1. Get API key: https://platform.openai.com/api-keys
20+
21+
2. Install packages:
22+
```bash
23+
pip3 install openai requests
24+
```
25+
26+
3. Set the key:
27+
```bash
28+
export OPENAI_API_KEY='sk-...'
29+
echo 'export OPENAI_API_KEY="sk-..."' >> ~/.bashrc
30+
```
31+
32+
macOS users also need:
33+
```bash
34+
echo 'export OPENAI_API_KEY="sk-..."' >> ~/.zshenv
35+
```
36+
37+
4. Configure nchat (`~/.config/nchat/ui.conf`):
38+
```conf
39+
audio_transcribe_enabled=1
40+
audio_transcribe_cache=1
41+
```
42+
43+
5. Test:
44+
```bash
45+
/usr/local/libexec/nchat/transcribe -f /path/to/test.ogg
46+
```
47+
48+
Monitor costs at https://platform.openai.com/usage (set a budget limit!)
49+
50+
---
51+
52+
## Option 2: whisper.cpp (Local Server)
53+
54+
Free, private, offline. Bit more setup. Fast with GPU.
55+
56+
**Setup:**
57+
58+
1. Install deps:
59+
```bash
60+
# macOS
61+
brew install ffmpeg cmake
62+
63+
# Linux
64+
sudo apt install build-essential ffmpeg cmake git # Debian/Ubuntu
65+
sudo dnf install gcc-c++ ffmpeg cmake git # Fedora
66+
```
67+
68+
2. Build it:
69+
```bash
70+
mkdir -p ~/whisper.cpp && cd ~/whisper.cpp
71+
git clone https://github.com/ggerganov/whisper.cpp.git .
72+
mkdir build && cd build
73+
cmake .. -DWHISPER_BUILD_SERVER=ON
74+
cmake --build . --config Release
75+
```
76+
77+
3. Download a model:
78+
```bash
79+
cd ~/whisper.cpp
80+
bash ./models/download-ggml-model.sh base # or tiny/small/medium/large
81+
```
82+
83+
4. Start the server:
84+
```bash
85+
cd ~/whisper.cpp
86+
./build/bin/server --model models/ggml-base.bin --host 127.0.0.1 --port 8080 --convert
87+
```
88+
89+
Run in background:
90+
```bash
91+
nohup ./build/bin/server --model models/ggml-base.bin --host 127.0.0.1 --port 8080 --convert > server.log 2>&1 &
92+
```
93+
94+
5. Install Python package:
95+
```bash
96+
pip3 install requests
97+
```
98+
99+
6. Configure nchat:
100+
```conf
101+
audio_transcribe_enabled=1
102+
audio_transcribe_command=/usr/local/libexec/nchat/transcribe -f '%1' -s whisper-cpp
103+
audio_transcribe_cache=1
104+
```
105+
106+
7. Test:
107+
```bash
108+
curl http://localhost:8080/health
109+
/usr/local/libexec/nchat/transcribe -f /path/to/test.ogg -s whisper-cpp
110+
```
111+
112+
**Want auto-start on boot?** Set up a systemd service (Linux) or launchd (macOS) - Google it.
113+
114+
---
115+
116+
## Option 3: Whisper Python (Local)
117+
118+
Free, private, simple. Slower than whisper.cpp, uses more RAM.
119+
120+
**Setup:**
121+
122+
1. Install ffmpeg:
123+
```bash
124+
brew install ffmpeg # macOS
125+
sudo apt install ffmpeg python3-dev # Debian/Ubuntu
126+
sudo dnf install ffmpeg python3-devel # Fedora
127+
```
128+
129+
2. Install Whisper:
130+
```bash
131+
pip3 install faster-whisper # Faster (recommended)
132+
# or
133+
pip3 install openai-whisper # Original (slower)
134+
```
135+
136+
3. Configure nchat:
137+
```conf
138+
audio_transcribe_enabled=1
139+
audio_transcribe_command=/usr/local/libexec/nchat/transcribe -f '%1' -s whisper-local -m base
140+
audio_transcribe_cache=1
141+
```
142+
143+
4. Test:
144+
```bash
145+
/usr/local/libexec/nchat/transcribe -f /path/to/test.ogg -s whisper-local
146+
```
147+
148+
Models download automatically on first use. Pick a size: `tiny` (fast, meh), `base` (balanced), `small`/`medium`/`large` (slower, better).
149+
150+
Got an NVIDIA GPU? Use `pip3 install faster-whisper[gpu]` after installing CUDA.
151+
152+
---
153+
154+
## Option 4: Groq API (Cheaper Alternative)
155+
156+
Like OpenAI but cheaper ($0.001/min vs $0.006/min). Still fast.
157+
158+
**Setup:**
159+
160+
1. Get API key from https://console.groq.com/
161+
162+
2. Install:
163+
```bash
164+
pip3 install groq requests
165+
```
166+
167+
3. Set key:
168+
```bash
169+
export GROQ_API_KEY='gsk-...'
170+
echo 'export GROQ_API_KEY="gsk-..."' >> ~/.bashrc
171+
echo 'export GROQ_API_KEY="gsk-..."' >> ~/.zshenv # macOS
172+
```
173+
174+
4. You'll need to hack the transcribe script to add Groq support (it's not built-in yet). Or just use OpenAI.
175+
176+
---
177+
178+
## Testing
179+
180+
After setup:
181+
182+
```bash
183+
# Test the script
184+
/usr/local/libexec/nchat/transcribe -f /path/to/test.ogg
185+
186+
# Check nchat config
187+
grep transcribe ~/.config/nchat/ui.conf
188+
```
189+
190+
In nchat: Select a voice message, press `Alt-u`, see if it works.
191+
192+
---
193+
194+
## Troubleshooting
195+
196+
**"Command not found"**
197+
```bash
198+
ls -l /usr/local/libexec/nchat/transcribe # Check if it exists
199+
```
200+
201+
**"No module named 'openai'"**
202+
```bash
203+
pip3 install openai # or whatever package is missing
204+
```
205+
206+
**"API key not set"**
207+
```bash
208+
echo $OPENAI_API_KEY # Check it's set
209+
echo 'export OPENAI_API_KEY="sk-..."' >> ~/.bashrc
210+
echo 'export OPENAI_API_KEY="sk-..."' >> ~/.zshenv # macOS
211+
```
212+
213+
**whisper.cpp server not responding**
214+
```bash
215+
curl http://localhost:8080/health # Check if running
216+
cd ~/whisper.cpp && ./build/bin/server --model models/ggml-base.bin --host 127.0.0.1 --port 8080 --convert
217+
```
218+
219+
**Timeouts**
220+
```conf
221+
audio_transcribe_timeout=60 # Increase in ui.conf
222+
```
223+
224+
**Need ffmpeg**
225+
```bash
226+
brew install ffmpeg # macOS
227+
sudo apt install ffmpeg # Linux
228+
```
229+
230+
**High CPU/RAM**
231+
232+
Use a smaller model (`-m tiny`), or switch to whisper.cpp, or just use the API.
233+
234+
---
235+
236+
## Quick Comparison
237+
238+
| Option | Speed | Privacy | Cost | Setup |
239+
|--------|-------|---------|------|-------|
240+
| OpenAI | Fast | Low | $0.006/min | Easy |
241+
| whisper.cpp | Good | High | Free | Medium |
242+
| Whisper Python | OK | High | Free | Easy |
243+
| Groq | Fast | Low | $0.001/min | Easy |
244+
245+
Pick what works for you.

0 commit comments

Comments
 (0)