airi with subtitle and translate#1496
Conversation
字幕文件,自行填写注释的内容, DeepSeek API Key,百度翻译AppID,百度翻译密钥(注意区分“密钥”与“api key”)
创建本地url的代码(最后一行):uvicorn.run(app, host="127.0.0.1", port=9000, log_level="info") 此处默认的是http://localhost:9000,在chat服务里的Base URL就填这个 其他相关信息在代码里有注释。 可以设定special words,用来将特定的内容翻译为你期望的内容
字幕文本文件,被proxy-llm与subtitlepy读取
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 681a9b8cd9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| text = chunk.decode('utf-8', errors='ignore') | ||
| lines = text.split('\n') | ||
| for line in lines: | ||
| line = line.strip() | ||
| if line.startswith('data: ') and '[DONE]' not in line: |
There was a problem hiding this comment.
Buffer SSE fragments before parsing deltas
Treating each aiter_bytes() chunk as complete SSE lines is unsafe because chunk boundaries are arbitrary; JSON payloads are often split across chunks. In that case line.startswith('data: ')/json.loads(...) misses fragments and silently skips them, so content_parts becomes incomplete and the subtitle text can drop words or entire segments under normal network conditions.
Useful? React with 👍 / 👎.
| ) | ||
|
|
||
| try: | ||
| resp = httpx.get(url, timeout=15) |
There was a problem hiding this comment.
Avoid blocking the event loop during translation
This endpoint is async, but baidu_translate performs a synchronous httpx.get call. When translation runs, the event loop is blocked for up to the timeout, which stalls other concurrent streaming requests and can delay or freeze responses in multi-client usage. Use an async client call from the request context instead.
Useful? React with 👍 / 👎.
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
|
这也太胶水了 不如去开个feature request等人好好实现吧 |
感谢你的建议!其实本来就自己做出来用的,但官方的人貌似希望做个参考,叫我做了个PR。完全没有动源代码主要是因为把源代码全部理解一遍太困难了,做个外置的简单些还能顺便做字幕并适配后续版本。 |
Description
添加了字幕与翻译的代理程序
subtitle.txt:字幕文本内容存放的位置
proxy-llm.py:代理,填写百度翻译所需要的信息(密钥,url之类的)
subtitlepy.py:字幕