Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(voice,install): play piper without system codecs, name a python without ssl

purpleda27757aae4a
diff --git a/src-tauri/src/commands/install.rs b/src-tauri/src/commands/install.rs
index 048207fc..3c4070fb 100644
--- a/src-tauri/src/commands/install.rs
+++ b/src-tauri/src/commands/install.rs
@@ -330,6 +330,16 @@ fn diagnose_pip_error_inner(stderr: &str) -> String {
• Arch: sudo pacman -S python-virtualenv\n\
• Debian/Ubuntu: sudo apt install python3-venv\n\
• Fedora: sudo dnf install python3-virtualenv"
+ } else if lower.contains("ssl module in python is not available") {
+ // numbrain (Discord, 2026-08-02): a pyenv/source-built python without
+ // the _ssl extension can't reach pypi AT ALL, and the generic SSL hint
+ // below (antivirus/clock) sent him in the wrong direction.
+ "This Python was built without the ssl module, so pip cannot reach \
+ pypi.org at all. Use your distro's regular python3 (it ships with \
+ ssl): check with python3 -c \"import ssl\" — if that fails, \
+ reinstall python3 via your package manager (pyenv builds need the \
+ OpenSSL headers installed first, e.g. libssl-dev / openssl-devel), \
+ then retry."
} else if lower.contains("ssl") {
"SSL error reaching pypi.org. Often caused by an antivirus / firewall \
intercepting TLS, or a stale system clock. Disable TLS interception \
@@ -3483,6 +3493,20 @@ mod tests {
assert!(lower.contains("antivirus") || lower.contains("firewall") || lower.contains("clock"));
}
+ #[test]
+ fn a_python_without_ssl_is_named_not_blamed_on_antivirus() {
+ // numbrain's exact pip wording (Discord 2026-08-02): the interpreter
+ // itself has no _ssl, so the antivirus/clock hint is the wrong trail.
+ let msg = diagnose_pip_error(
+ "WARNING: pip is configured with locations that require TLS/SSL, \
+ however the ssl module in Python is not available.",
+ );
+ let lower = msg.to_lowercase();
+ assert!(lower.contains("built without the ssl module"));
+ assert!(lower.contains("import ssl"));
+ assert!(!lower.contains("antivirus"));
+ }
+
#[test]
fn diagnose_403_suggests_vpn() {
let msg = diagnose_pip_error("HTTP 403 from pytorch.org");
diff --git a/src/api/__tests__/voice-wav-parse.test.ts b/src/api/__tests__/voice-wav-parse.test.ts
new file mode 100644
index 00000000..27049f4d
--- /dev/null
+++ b/src/api/__tests__/voice-wav-parse.test.ts
@@ -0,0 +1,70 @@
+import { describe, it, expect } from 'vitest'
+import { parseWavPcm } from '../voice'
+
+// The codec-free playback fallback (GH #77) stands on this parser: a Windows
+// N edition plays nothing through HTMLAudioElement, so the wav bytes must
+// decode by hand. Build real RIFF files in-memory and walk every branch.
+
+function wav16(opts: { sampleRate?: number; channels?: number; frames?: number } = {}) {
+ const { sampleRate = 22050, channels = 1, frames = 4 } = opts
+ const dataLen = frames * channels * 2
+ const buf = new ArrayBuffer(44 + dataLen)
+ const v = new DataView(buf)
+ const w = (o: number, s: string) => { for (let i = 0; i < s.length; i++) v.setUint8(o + i, s.charCodeAt(i)) }
+ w(0, 'RIFF'); v.setUint32(4, 36 + dataLen, true); w(8, 'WAVE')
+ w(12, 'fmt '); v.setUint32(16, 16, true)
+ v.setUint16(20, 1, true) // PCM
+ v.setUint16(22, channels, true)
+ v.setUint32(24, sampleRate, true)
+ v.setUint32(28, sampleRate * channels * 2, true)
+ v.setUint16(32, channels * 2, true)
+ v.setUint16(34, 16, true)
+ w(36, 'data'); v.setUint32(40, dataLen, true)
+ return { buf, view: v, dataAt: 44 }
+}
+
+describe('parseWavPcm', () => {
+ it('decodes the wav piper writes: 16-bit mono PCM', () => {
+ const { buf, view, dataAt } = wav16({ frames: 3 })
+ view.setInt16(dataAt, 32767, true)
+ view.setInt16(dataAt + 2, -32768, true)
+ view.setInt16(dataAt + 4, 0, true)
+ const out = parseWavPcm(buf)!
+ expect(out.sampleRate).toBe(22050)
+ expect(out.channels).toHaveLength(1)
+ expect(out.channels[0][0]).toBeCloseTo(1, 3)
+ expect(out.channels[0][1]).toBe(-1)
+ expect(out.channels[0][2]).toBe(0)
+ })
+
+ it('deinterleaves stereo frames into separate channels', () => {
+ const { buf, view, dataAt } = wav16({ channels: 2, frames: 2 })
+ view.setInt16(dataAt, 16384, true) // L0
+ view.setInt16(dataAt + 2, -16384, true) // R0
+ view.setInt16(dataAt + 4, 8192, true) // L1
+ view.setInt16(dataAt + 6, -8192, true) // R1
+ const out = parseWavPcm(buf)!
+ expect(out.channels).toHaveLength(2)
+ expect(out.channels[0][0]).toBeCloseTo(0.5, 3)
+ expect(out.channels[1][0]).toBeCloseTo(-0.5, 3)
+ expect(out.channels[0][1]).toBeCloseTo(0.25, 3)
+ })
+
+ it('refuses what it cannot decode instead of guessing', () => {
+ expect(parseWavPcm(new ArrayBuffer(10))).toBeNull()
+ // mp3 magic bytes are not RIFF
+ const mp3 = new Uint8Array(64); mp3[0] = 0xff; mp3[1] = 0xfb
+ expect(parseWavPcm(mp3.buffer)).toBeNull()
+ // RIFF but a compressed format code (2 = ADPCM) stays with decodeAudioData
+ const { buf, view } = wav16()
+ view.setUint16(20, 2, true)
+ expect(parseWavPcm(buf)).toBeNull()
+ })
+
+ it('survives a data chunk whose declared size overruns the file', () => {
+ const { buf, view } = wav16({ frames: 4 })
+ view.setUint32(40, 9999, true) // lies about its length
+ const out = parseWavPcm(buf)!
+ expect(out.channels[0]).toHaveLength(4)
+ })
+})
diff --git a/src/api/voice.ts b/src/api/voice.ts
index cab9fbf0..f054e55b 100644
--- a/src/api/voice.ts
+++ b/src/api/voice.ts
@@ -414,6 +414,86 @@ export async function listInstalledPiperVoices(): Promise<string[]> {
let neuralAudio: HTMLAudioElement | null = null;
let neuralAudioDone: (() => void) | null = null;
+let webAudioPlayback: { source: AudioBufferSourceNode; done: () => void } | null = null;
+
+/** Parse a PCM WAV (16-bit int or 32-bit float, the formats piper and every
+ * TTS wav here produce) into raw channel data. Pure byte-walking on the RIFF
+ * chunks, no platform decoder involved — that independence is the point (see
+ * playNeuralAudio). Returns null for anything that isn't such a wav. */
+export function parseWavPcm(
+ bytes: ArrayBuffer,
+): { sampleRate: number; channels: Float32Array[] } | null {
+ const view = new DataView(bytes);
+ if (bytes.byteLength < 44) return null;
+ if (view.getUint32(0, false) !== 0x52494646) return null; // 'RIFF'
+ if (view.getUint32(8, false) !== 0x57415645) return null; // 'WAVE'
+
+ let format = 0, channelCount = 0, sampleRate = 0, bitsPerSample = 0;
+ let data: { offset: number; length: number } | null = null;
+ let pos = 12;
+ while (pos + 8 <= bytes.byteLength) {
+ const id = view.getUint32(pos, false);
+ const size = view.getUint32(pos + 4, true);
+ if (id === 0x666d7420) { // 'fmt '
+ format = view.getUint16(pos + 8, true);
+ channelCount = view.getUint16(pos + 10, true);
+ sampleRate = view.getUint32(pos + 12, true);
+ bitsPerSample = view.getUint16(pos + 22, true);
+ } else if (id === 0x64617461) { // 'data'
+ data = { offset: pos + 8, length: Math.min(size, bytes.byteLength - pos - 8) };
+ }
+ pos += 8 + size + (size % 2); // chunks are word-aligned
+ }
+ const pcm16 = format === 1 && bitsPerSample === 16;
+ const float32 = format === 3 && bitsPerSample === 32;
+ if (!data || !channelCount || !sampleRate || (!pcm16 && !float32)) return null;
+
+ const bytesPerSample = bitsPerSample / 8;
+ const frames = Math.floor(data.length / (bytesPerSample * channelCount));
+ if (frames === 0) return null;
+ const channels = Array.from({ length: channelCount }, () => new Float32Array(frames));
+ for (let f = 0; f < frames; f++) {
+ for (let c = 0; c < channelCount; c++) {
+ const at = data.offset + (f * channelCount + c) * bytesPerSample;
+ channels[c][f] = pcm16 ? view.getInt16(at, true) / 32768 : view.getFloat32(at, true);
+ }
+ }
+ return { sampleRate, channels };
+}
+
+/** Codec-free playback path: hand-parsed PCM into Web Audio, with Chromium's
+ * bundled decodeAudioData for compressed formats. Used when the media element
+ * fails (ElBiggus GH #77: on a Windows N edition without the Media Feature
+ * Pack, `new Audio(wav)` errors even though piper wrote a perfect wav —
+ * HTMLAudioElement decodes through Media Foundation, Web Audio does not). */
+async function playViaWebAudio(dataUrl: string): Promise<void> {
+ const bytes = await (await fetch(dataUrl)).arrayBuffer();
+ const ctx = new AudioContext();
+ try {
+ const pcm = parseWavPcm(bytes);
+ let buffer: AudioBuffer;
+ if (pcm) {
+ buffer = ctx.createBuffer(pcm.channels.length, pcm.channels[0].length, pcm.sampleRate);
+ pcm.channels.forEach((ch, i) => buffer.copyToChannel(ch, i));
+ } else {
+ buffer = await ctx.decodeAudioData(bytes);
+ }
+ await ctx.resume().catch(() => { /* best effort */ });
+ await new Promise<void>((resolve) => {
+ const source = ctx.createBufferSource();
+ source.buffer = buffer;
+ source.connect(ctx.destination);
+ webAudioPlayback = { source, done: resolve };
+ source.onended = () => {
+ if (webAudioPlayback?.source === source) webAudioPlayback = null;
+ resolve();
+ };
+ source.start();
+ });
+ } finally {
+ void ctx.close().catch(() => { /* already closed */ });
+ }
+}
/** Play a WAV data URL or MP3 blob URL; resolves when playback ends (or is
* stopped via stopNeuralAudio). Replaces any current clip. Object URLs are
@@ -426,14 +506,20 @@ export function playNeuralAudio(dataUrl: string): Promise<void> {
if (neuralAudio === audio) { neuralAudio = null; neuralAudioDone = null; }
if (dataUrl.startsWith("blob:")) URL.revokeObjectURL(dataUrl);
};
+ // Media element failed — retry through Web Audio before giving up. The
+ // blob: URL must stay alive until the fallback has fetched it, so this
+ // path revokes late instead of via cleanup().
+ const fallback = () => {
+ if (neuralAudio === audio) { neuralAudio = null; neuralAudioDone = null; }
+ playViaWebAudio(dataUrl)
+ .then(resolve, () => reject(new Error("neural audio playback failed")))
+ .finally(() => { if (dataUrl.startsWith("blob:")) URL.revokeObjectURL(dataUrl); });
+ };
neuralAudio = audio;
neuralAudioDone = () => { cleanup(); resolve(); };
audio.onended = () => { cleanup(); resolve(); };
- audio.onerror = () => {
- cleanup();
- reject(new Error("neural audio playback failed"));
- };
- audio.play().catch((err) => { cleanup(); reject(err); });
+ audio.onerror = fallback;
+ audio.play().catch(fallback);
});
}
@@ -448,6 +534,14 @@ export function stopNeuralAudio(): void {
neuralAudioDone = null;
done?.();
}
+ if (webAudioPlayback) {
+ // Same contract for the Web Audio fallback: stop() fires onended, but
+ // settle explicitly in case the source never started.
+ const { source, done } = webAudioPlayback;
+ webAudioPlayback = null;
+ try { source.stop(); } catch { /* never started */ }
+ done();
+ }
}
// --- Audio Recorder (Web Audio PCM → 16 kHz mono WAV) ---