From 759df2cc3c3fc33b644a3c6854936e5e017e8ef3 Mon Sep 17 00:00:00 2001 From: Emilia <51059882+Allamaris0@users.noreply.github.com> Date: Fri, 13 Sep 2024 12:50:02 +0200 Subject: [PATCH] Update PyDeepLX.py fix payload --- PyDeepLX/PyDeepLX.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/PyDeepLX/PyDeepLX.py b/PyDeepLX/PyDeepLX.py index fce3b68..c89ead8 100644 --- a/PyDeepLX/PyDeepLX.py +++ b/PyDeepLX/PyDeepLX.py @@ -83,11 +83,13 @@ def translate( }, "timestamp": getTimestamp(iCount), "commonJobParams": { - "wasSpoken": False, - "transcribe_as": "", + "quality": "normal", + "mode": "translate", + "textType": "plaintext" }, }, } + postDataStr = json.dumps(postData, ensure_ascii=False) if (id + 5) % 29 == 0 or (id + 3) % 13 == 0: @@ -117,10 +119,18 @@ def translate( return targetText targetTextArray = [] - for item in respJson["result"]["texts"][0]["alternatives"]: - targetTextArray.append(item["text"]) + alternatives = respJson["result"]["texts"][0]["alternatives"] + if len(alternatives) == 0: + print("No found alternatives") + targetText = respJson["result"]["texts"][0]["text"] + targetTextArray.append(targetText) if printResult: - print(item["text"]) + print(targetText) + else: + for item in alternatives: + targetTextArray.append(item["text"]) + if printResult: + print(item["text"]) return targetTextArray