From 300c9031aa96df63987138fd169f10be3443b26d Mon Sep 17 00:00:00 2001 From: Dazed Date: Thu, 2 Nov 2023 18:01:27 -0500 Subject: [PATCH] Fix newline issue in tyrano --- modules/lune.py | 13 ++++++++++--- modules/tyrano.py | 9 ++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/lune.py b/modules/lune.py index 9f0557f..e681e06 100644 --- a/modules/lune.py +++ b/modules/lune.py @@ -25,7 +25,7 @@ APICOST = .002 # Depends on the model https://openai.com/pricing PROMPT = Path('prompt.txt').read_text(encoding='utf-8') THREADS = 20 LOCK = threading.Lock() -WIDTH = 75 +WIDTH = 60 LISTWIDTH = 75 MAXHISTORY = 10 ESTIMATE = '' @@ -129,7 +129,6 @@ def translateText(data, pbar): tokens = 0 speaker = '' speakerFlag = False - currentGroup = [] syncIndex = 0 ### Translation @@ -143,6 +142,7 @@ def translateText(data, pbar): # Remove newlines jaString = data[i] + jaString = jaString.replace('\\n', '') jaString = jaString.replace('\n', '') # Reset Speaker @@ -179,6 +179,11 @@ def translateText(data, pbar): # Translate finalJAString = data[i] + + # Remove Textwrap + finalJAString = finalJAString.replace('\\n', ' ') + finalJAString = finalJAString.replace('\n', ' ') + if speaker != '': response = translateGPT(f'{speaker}: {finalJAString}', 'Previous Text for Context: ' + ' '.join(textHistory), True) else: @@ -201,8 +206,10 @@ def translateText(data, pbar): currentGroup = [] # Textwrap - translatedText = textwrap.fill(translatedText, width=40) + translatedText = textwrap.fill(translatedText, width=WIDTH) + translatedText = translatedText.replace(',\n', ', \n') translatedText = translatedText.replace('\n', '\\n') + translatedText = translatedText.replace(',\\n', ', \\n') # Set Data data[i] = translatedText + '\n' diff --git a/modules/tyrano.py b/modules/tyrano.py index 471782f..9694bc6 100644 --- a/modules/tyrano.py +++ b/modules/tyrano.py @@ -123,6 +123,9 @@ def translateTyrano(data, pbar): if syncIndex > i: i = syncIndex + if '… …… ………[pcm]' in data[i]: + print('test') + # Speaker if '[ns]' in data[i]: matchList = re.findall(r'\[ns\](.+?)\[', data[i]) @@ -160,7 +163,7 @@ def translateTyrano(data, pbar): data[i] = translatedText # Lines - matchList = re.findall(r'(.+?)\[r\]$', data[i]) + matchList = re.findall(r'(.+?)\[r\]', data[i]) if len(matchList) > 0: matchList[0] = matchList[0].replace('「', '') matchList[0] = matchList[0].replace('」', '') @@ -264,7 +267,7 @@ def translateTyrano(data, pbar): speaker = '' # pcm Line - matchList = re.findall(r'(.+?)\[pcm\]$', data[i]) + matchList = re.findall(r'(.+?)\[pcm\]', data[i]) if len(matchList) > 0: matchList[0] = matchList[0].replace('「', '') matchList[0] = matchList[0].replace('」', '') @@ -339,7 +342,7 @@ def translateTyrano(data, pbar): translatedText = translatedText.replace('\n', '[r]') # Set Backup - data[i] = translatedText.strip() + '[pcm]' + data[i] = translatedText.strip() + '[pcm]\n' # Keep textHistory list at length maxHistory if len(textHistory) > maxHistory: