{"record":{"id":"a8de7edf6144463e","repo":"SubtitleEdit/subtitleedit","slug":"cosyvoice3-crispasr-synthesis-failed-int-resp","errorCode":null,"errorMessage":"CosyVoice3 (CrispASR) synthesis failed ({(int)response.StatusCode}): {errorBody}","messagePattern":"CosyVoice3 \\(CrispASR\\) synthesis failed \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/ui/Features/Video/TextToSpeech/Engines/CosyVoice3CrispAsr.cs","lineNumber":610,"sourceCode":"                + (string.IsNullOrEmpty(serverLog) ? string.Empty : $\"{Environment.NewLine}Server log:{Environment.NewLine}{serverLog}\")\n                + LaunchCmdSuffix(launchCommand),\n                ex);\n        }\n\n        using (response)\n        {\n            if (!response.IsSuccessStatusCode)\n            {\n                var errorBody = await SafeReadErrorAsync(response, cancellationToken);\n                var serverLog = SnapshotServerLog();\n                var launchCommand = _serverLaunchCommand;\n                var errMsg = $\"CosyVoice3 (CrispASR) server error {(int)response.StatusCode} {response.StatusCode} — \"\n                    + $\"Voice: {cosyVoice}, Text: {text}, RequestJson: {body}, \"\n                    + $\"ResponseBody: {errorBody}, ServerLog: {serverLog}\"\n                    + LaunchCmdSuffix(launchCommand);\n                Se.LogError(errMsg);\n                Se.WriteToolsLog(errMsg);\n                throw new InvalidOperationException(\n                    $\"CosyVoice3 (CrispASR) synthesis failed ({(int)response.StatusCode}): {errorBody}\"\n                    + (string.IsNullOrEmpty(serverLog) ? string.Empty : $\"{Environment.NewLine}Server log:{Environment.NewLine}{serverLog}\")\n                    + LaunchCmdSuffix(launchCommand));\n            }\n\n            await using var fileStream = File.Create(outputFileName);\n            await using var contentStream = await response.Content.ReadAsStreamAsync(cancellationToken);\n            await contentStream.CopyToAsync(fileStream, cancellationToken);\n        }\n\n        return new TtsResult(outputFileName, text);\n    }\n\n    private static string FormatLaunchCommand(string exe, System.Collections.ObjectModel.Collection<string> args)\n    {\n        static string Quote(string s) =>\n            !string.IsNullOrEmpty(s) && s.IndexOfAny(new[] { ' ', '\\t' }) >= 0\n                ? \"\\\"\" + s.Replace(\"\\\"\", \"\\\\\\\"\") + \"\\\"\"","sourceCodeStart":592,"sourceCodeEnd":628,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Features/Video/TextToSpeech/Engines/CosyVoice3CrispAsr.cs#L592-L628","documentation":"InvalidOperationException from CosyVoice3CrispAsr.Speak when the /v1/audio/speech POST returns a non-success HTTP status. The numeric status, the response body (via SafeReadErrorAsync), and the server log are all folded into the message; the detailed diagnostic is also written via Se.LogError/Se.WriteToolsLog.","triggerScenarios":"crispasr returns 4xx/5xx for the synthesis request — e.g. HTTP 400 for a malformed voice/language/source_lang combo, 422 for unsupported input, 500 for a backend error that did not kill the process, or 503 while the model is still loading.","commonSituations":"Sending an unsupported language code; a voice preset name the backend rejects; a zero-shot clone missing the required ref-text; the server still warming up (503); a backend bug returning 500.","solutions":["Read the status code: 4xx → fix the request payload (language, voice, source_lang); 5xx → server/backend fault.","Cross-check language/source_lang values against CosyVoice3Languages; leave empty for auto if unsupported.","For zero-shot clones, ensure a reference transcription is set (the startup --ref-text).","On 503, wait for the server to finish loading and retry; the health probe gates startup but not warm-up.","Inspect 'Server log' for the backend-side stack trace behind a 500."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate language/source_lang against the resolver before posting.\nvar langArg = CosyVoice3Languages.ResolveLanguageArg(language);\nif (!string.IsNullOrEmpty(langArg) && !CosyVoice3Languages.All.Any(l => l.Code == langArg))\n    return new TtsResult { Text = text, FileName = string.Empty, Error = true, ErrorMessage = $\"Unsupported language {langArg}\" };","typeGuard":null,"tryCatchPattern":"try { await cosyVoice3Engine.Speak(text, out, voice, lang, region, model, ct); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"synthesis failed (\", StringComparison.Ordinal))\n{\n    var code = ExtractStatusCode(ex.Message);\n    if (code == 503) { await Task.Delay(TimeSpan.FromSeconds(5), ct); await cosyVoice3Engine.Speak(text, out, voice, lang, region, model, ct); }\n    else Se.WriteToolsLog($\"CosyVoice3 synthesis HTTP {code}: {ex.Message}\", true);\n}","preventionTips":["Cross-check language/source_lang values against CosyVoice3Languages before sending.","For zero-shot clones, ensure a reference transcription is set.","On 503, wait for warm-up and retry rather than failing immediately."],"tags":["tts","cosyvoice3","crispasr","http-error","synthesis","request-payload"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}