bug: JSON parsing failures in audio2subtitle.go due to LLM conversational text and trailing commas
前置检查
- 我已经搜索过现有的 Issues,确认没有重复的问题。
- 我已经阅读了项目的文档(如果有的话),但没有找到解决方案。
- 我使用的是最新版本的软件。
Bug 描述 (Bug Description)
Hi, I am using Klic Studio Desktop version 1.4 locally with Ollama (llama3.1).
During the transcription/translation process, the application frequently encounters JSON parsing errors in audio2subtitle.go. The application is robust enough to skip the failed splits and continue, but it leads to missing translations or poorly split sentences in the final output.
There are two distinct scenarios causing the internal Go JSON parser to fail:
Scenario 1: Trailing Commas in JSON Arrays/Objects
The LLM generates valid-looking JSON but includes trailing commas (e.g., after the last text element or object), which throws an invalid character '}' error.
Scenario 2: Conversational Prefixes/Suffixes (e.g., Chinese markdown wrappers)
Since the hidden system prompt seems to be in Chinese, Llama 3.1 often responds with conversational Chinese introductions before emitting the markdown JSON block (e.g., "以下是分割后的结果:\n\n```json..."). The Go parser interprets the UTF-8 Chinese bytes as invalid characters like 'ä' and crashes.
复现步骤 (Steps to Reproduce)
- choose a video with english audio
- no bilingual subtitles, original language: English / Translate to: Deutsch (German)
- Apply dubbing with voice: de-DE-ConradNeural llm with ollama API Base url: http://localhost:11434/v1 model: llama3.1 fasterwhisper with model tiny edge-tts
✅ 预期行为 (Expected Behavior)
Suggested Fixes:
- Sanitize LLM Responses: Implement a regex or substring filter in
audio2subtitle.goto extract only the string between the first{and the last}(or parse insidejson ...blocks) before feeding it into the JSON parser. - Enable Structured Outputs: If possible, utilize the official JSON Mode / Structured Outputs schema for OpenAI-compatible APIs to force Ollama to return raw, valid JSON without conversational fluff.
❌ 实际行为 (Actual Behavior)
see description above
错误日志 (Error Log)
Log output scenario1:
error service/audio2subtitle.go:1334 splitOriginLongSentence parse split result error {"error": "invalid character '}' looking for beginning of object key string", "response": "{\n\"short_sentences\":[{\n\"text\": \"And the reason why they chose the owl is because\",\n},\n{\n\"text\": \"the owl is a symbol used in Europe...\",\n}] \n}"}
Log output scenario2:
2026-05-27T13:26:51.658+0200 error service/audio2subtitle.go:1297 splitLongSentence parse split result error {"error": "invalid character 'ä' looking for beginning of value", "response": "以下是分割后的结果:\n\n\n{\n \"align\": [\n { \"origin_part\": \"I want to show you\", \"translated_part\": \"Ich möchte es Ihnen zeigen\" },...\n ]\n}\n"}Source: krillinai/KrillinAI