feat(python-subprocess): 尝试字幕显示新解决方案

- 使用 python 子进程解析字幕
- 通过 websocket 通信将字幕传递给软件
This commit is contained in:
himeditator
2025-06-15 12:43:57 +08:00
parent f10530eb67
commit 8858189bf6
18 changed files with 572 additions and 64 deletions

View File

@@ -1,8 +1,9 @@
from dashscope.audio.asr import \
TranslationRecognizerCallback, \
TranscriptionResult, \
TranslationResult, \
TranslationRecognizerRealtime
from dashscope.audio.asr import (
TranslationRecognizerCallback,
TranscriptionResult,
TranslationResult,
TranslationRecognizerRealtime
)
class Callback(TranslationRecognizerCallback):
"""
@@ -53,15 +54,15 @@ class Callback(TranslationRecognizerCallback):
if usage: self.usage += usage['duration']
def getGummpyTranslator(rate) -> TranslationRecognizerRealtime:
translator = TranslationRecognizerRealtime(
class GummyTranslator:
def __init__(self, rate, source, target):
self.translator = TranslationRecognizerRealtime(
model = "gummy-realtime-v1",
format = "pcm",
sample_rate = rate,
transcription_enabled = True,
translation_enabled = True,
source_language = "ja",
translation_target_languages = ["zh"],
source_language = source,
translation_target_languages = [target],
callback = Callback()
)
return translator
)