chenhg5/cc-connect · error

edge-tts: read output file: %w

Error message

edge-tts: read output file: %w

What it means

EdgeTTS.Synthesize (core/tts.go:715) reads back the MP3 temp file that the edge-tts CLI was told to write via --write-media. This error wraps os.ReadFile failure after the CLI exited 0, meaning the output file vanished, was never created at the expected path, or is unreadable. It indicates a mismatch between where the CLI wrote (or failed to write) and where the library reads.

Source

Thrown at core/tts.go:715

		"--voice", voice,
		"--text", text,
		"--write-media", tmpPath,
	}

	path := e.Path
	if path == "" {
		path = "edge-tts"
	}
	cmd := exec.CommandContext(ctx, path, args...)
	output, err := cmd.CombinedOutput()
	if err != nil {
		return nil, "", fmt.Errorf("edge-tts: voice=%s text=%q: %w, output: %s", voice, text, err, string(output))
	}

	// Read the generated MP3 file
	audioData, err := os.ReadFile(tmpPath)
	if err != nil {
		return nil, "", fmt.Errorf("edge-tts: read output file: %w", err)
	}

	if len(audioData) == 0 {
		return nil, "", fmt.Errorf("edge-tts: produced empty audio file")
	}

	return audioData, "mp3", nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check nothing is purging /tmp during synthesis (systemd-tmpfiles age settings, tmpwatch, custom cleanup jobs)
  2. Run the exact command manually (`edge-tts --voice <v> --text 'test' --write-media /tmp/x.mp3`) to confirm it actually creates the file
  3. Upgrade edge-tts; some versions exit 0 on failure without writing the output file
  4. Check file permissions and that TMPDIR is on a normal local filesystem, not a special mount
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := exec.LookPath("edge-tts"); err != nil {
    return errors.New("edge-tts CLI not installed")
}
// ensure no tmp reaper races the synthesis
out, err := exec.Command("edge-tts", "--voice", voice, "--text", "ping", "--write-media", "/tmp/tts_check.mp3").Output()
_ = out; _ = err

Try / catch

audio, format, err := edge.Synthesize(ctx, text, opts)
if err != nil {
    if strings.Contains(err.Error(), "read output file") {
        slog.Warn("edge-tts output missing/unreadable; retrying once")
        audio, format, err = edge.Synthesize(ctx, text, opts)
    }
    if err != nil {
        return err
    }
}

Prevention

When it happens

Trigger: Calling EdgeTTS.Synthesize when os.ReadFile(tmpPath) fails after successful CLI exit — the temp file was deleted between creation and read (e.g. aggressive /tmp cleaner or another process using the same path), edge-tts exited 0 without writing --write-media output, or permission changes on the temp file made it unreadable.

Common situations: Environments running systemd-tmpfiles or security cleaners that race with the synthesis, custom e.Path wrappers that succeed without honoring --write-media, or odd mounts (FIFO/named volumes) where file creation semantics differ.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/02df098128cefc16. Report an issue: GitHub.