{"record":{"id":"9b25e34764153820","repo":"SubtitleEdit/subtitleedit","slug":"alltalk-tts-server-returned-error-int-result-sta","errorCode":null,"errorMessage":"AllTalk TTS server returned error {(int)result.StatusCode} ({result.StatusCode}).","messagePattern":"AllTalk TTS server returned error (.+?) \\((.+?)\\)\\.","errorType":"exception","errorClass":"HttpRequestException","httpStatus":null,"severity":"error","filePath":"src/ui/Logic/Download/TtsDownloadService.cs","lineNumber":178,"sourceCode":"        }\n        catch (HttpRequestException ex)\n        {\n            SeLogger.Error(ex, \"AllTalk TTS server connection failed.\");\n            throw new HttpRequestException(\"AllTalk TTS server is not reachable. Please check that the server is running.\", ex);\n        }\n        catch (TaskCanceledException ex) when (!cancellationToken.IsCancellationRequested)\n        {\n            SeLogger.Error(ex, \"AllTalk TTS server request timed out.\");\n            throw new HttpRequestException(\"AllTalk TTS server request timed out. Please check that the server is running.\", ex);\n        }\n\n        using (result)\n        {\n            if (!result.IsSuccessStatusCode)\n            {\n                var errorBody = await result.Content.ReadAsStringAsync(cancellationToken);\n                SeLogger.Error($\"AllTalk TTS failed calling API at {_httpClient.BaseAddress}: Status code={result.StatusCode}\" + Environment.NewLine + errorBody);\n                throw new HttpRequestException($\"AllTalk TTS server returned error {(int)result.StatusCode} ({result.StatusCode}).\");\n            }\n\n            var bytes = await result.Content.ReadAsByteArrayAsync(cancellationToken);\n            var resultJson = Encoding.UTF8.GetString(bytes);\n\n            var jsonParser = new SeJsonParser();\n            var allTalkOutput = jsonParser.GetFirstObject(resultJson, \"output_file_path\");\n            return allTalkOutput.Replace(\"\\\\\\\\\", \"\\\\\");\n        }\n    }\n\n    public async Task<bool> AllTalkIsInstalled()\n    {\n        // The old Task.WhenAny check reported \"installed\" whenever the request completed before\n        // the 2 s timeout - including completing by *faulting*, so a connection refused (server\n        // not running, ~instant) counted as installed and generation failed later instead.\n        try\n        {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/ui/Logic/Download/TtsDownloadService.cs#L160-L196","documentation":"HttpRequestException thrown after a successful transport-level response when result.IsSuccessStatusCode is false. The error body is read and logged, and the thrown message includes the numeric and symbolic status code so the user knows the server rejected the request.","triggerScenarios":"AllTalk /api/tts-generate returns a non-2xx (e.g. 400/401/500). errorBody is captured into the log; the thrown exception carries only the status code.","commonSituations":"Malformed multipart payload, missing required form fields (text/voice/language), server-side model error, expired autoplay_volume, or an AllTalk version that changed the API contract.","solutions":["Inspect the SeLogger entry for the full errorBody to see the server's reason.","Verify the multipart fields sent match the AllTalk API version in use.","Confirm the requested voice/language is valid on the server.","Update AllTalk to a compatible version or align the payload to its current API."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var url = Se.Settings.Video.TextToSpeech.AllTalkUrl.TrimEnd('/') + \"/api/tts-generate\";\n// sanity-check required form fields before sending\nif (string.IsNullOrWhiteSpace(text) || string.IsNullOrWhiteSpace(voice))\n{\n    throw new ArgumentException(\"AllTalk requires non-empty text and voice.\");\n}","typeGuard":null,"tryCatchPattern":"try { var audio = await ttsService.GenerateAllTalk(...); }\ncatch (HttpRequestException ex) when (ex.Message.Contains(\"server returned error\"))\n{\n    // read SeLogger for the server's errorBody; show status code to the user\n}","preventionTips":["Inspect the SeLogger errorBody line for the server's reason before retrying.","Validate multipart fields match the deployed AllTalk API version.","Don't retry 4xx blindly - fix the request first."],"tags":["network","http","tts","alltalk","status-code","csharp"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}