{"record":{"id":"f757c4c4de735cb5","repo":"chenhg5/cc-connect","slug":"edge-tts-voice-s-text-q-w-output-s","errorCode":null,"errorMessage":"edge-tts: voice=%s text=%q: %w, output: %s","messagePattern":"edge-tts: voice=(.+?) text=%q: %w, output: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":709,"sourceCode":"\ttmpFile.Close()\n\tdefer os.Remove(tmpPath)\n\n\t// Use edge-tts CLI directly to avoid code injection risks\n\t// Pass text via --text argument, not via embedded code\n\targs := []string{\n\t\t\"--voice\", voice,\n\t\t\"--text\", text,\n\t\t\"--write-media\", tmpPath,\n\t}\n\n\tpath := e.Path\n\tif path == \"\" {\n\t\tpath = \"edge-tts\"\n\t}\n\tcmd := exec.CommandContext(ctx, path, args...)\n\toutput, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"edge-tts: voice=%s text=%q: %w, output: %s\", voice, text, err, string(output))\n\t}\n\n\t// Read the generated MP3 file\n\taudioData, err := os.ReadFile(tmpPath)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"edge-tts: read output file: %w\", err)\n\t}\n\n\tif len(audioData) == 0 {\n\t\treturn nil, \"\", fmt.Errorf(\"edge-tts: produced empty audio file\")\n\t}\n\n\treturn audioData, \"mp3\", nil\n}\n","sourceCodeStart":691,"sourceCodeEnd":724,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L691-L724","documentation":"EdgeTTS.Synthesize (core/tts.go:709) executes the external edge-tts CLI with --voice/--text/--write-media and captures its combined output. This error is returned when the CLI exits non-zero; it wraps the exec error (including context cancellation/timeout) and includes the voice, text, and the CLI's stderr/stdout for diagnosis. Since edge-tts calls Microsoft's network service, most failures are network or service-side.","triggerScenarios":"Calling EdgeTTS.Synthesize when the edge-tts binary cannot run or fails: binary not found on PATH, no network connectivity or Microsoft's Edge TTS endpoint unreachable/blocked, edge-tts token/service error (403s from expired client tokens on outdated edge-tts versions), an invalid --voice name, context deadline exceeded during synthesis, or a Python edge-tts install that is broken.","commonSituations":"Developers hit this in air-gapped or firewalled environments, after Microsoft changes its TTS auth so old pip-installed edge-tts versions get EdgeTTSException/403, when the voice string is misspelled (e.g. 'zh-CN-Xiaoxiao' instead of 'zh-CN-XiaoxiaoNeural'), or when the CLI simply isn't installed (`command not found`).","solutions":["Read the 'output:' portion of the error to see the underlying CLI message; fix accordingly (missing binary, auth, network)","Install/upgrade edge-tts (`pip install -U edge-tts`) — outdated versions break when Microsoft rotates service tokens and return 403","Verify network access to Microsoft's speech endpoints (speech.platform.bing.com); check proxy/firewall and set HTTPS_PROXY if needed","Confirm the configured voice name is valid: `edge-tts --list-voices | grep Xiaoxiao`","Retry on transient network errors; check that ctx timeouts are not expiring prematurely"],"exampleFix":"// before\nEdgeTTS: { Voice: \"zh-CN-XiaoXiao\" } // invalid voice name\n// after\nEdgeTTS: { Voice: \"zh-CN-XiaoxiaoNeural\" } // valid name from `edge-tts --list-voices`","handlingStrategy":"try-catch","validationCode":"if _, err := exec.LookPath(\"edge-tts\"); err != nil {\n    return errors.New(\"edge-tts CLI not found on PATH; install with: pip install edge-tts\")\n}\nif strings.TrimSpace(text) == \"\" {\n    return errors.New(\"empty text for TTS\")\n}","typeGuard":null,"tryCatchPattern":"audio, format, err := edge.Synthesize(ctx, text, opts)\nif err != nil {\n    var ctxErr error\n    if errors.Is(ctx.Err(), context.DeadlineExceeded) || strings.Contains(err.Error(), \"context\") {\n        return fmt.Errorf(\"edge-tts timed out: %w\", err)\n    }\n    if strings.Contains(err.Error(), \"403\") || strings.Contains(err.Error(), \"Exception\") {\n        return fmt.Errorf(\"edge-tts service rejected request (upgrade edge-tts): %w\", err)\n    }\n    return fmt.Errorf(\"edge-tts failed: %w\", err)\n}","preventionTips":["Pin and regularly upgrade the edge-tts package; old versions break when Microsoft rotates service tokens","Verify network/proxy reachability of Microsoft speech endpoints in your deployment environment","Validate voice names against `edge-tts --list-voices` before configuring them","Set a sane context timeout and treat 403/exception output as an upgrade signal","Keep a fallback TTS backend for offline or degraded network conditions"],"tags":["tts","edge-tts","external-cli","network","microsoft"],"backgroundTag":"http-error-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}