updated narrator splitting function

Improved over what was before. 
Still more work to do in future though.
This commit is contained in:
erew123 authored and GitHub committed 2023-12-28 18:39:01 +00:00
1 parent 8d80151889
commit acc457436a
1 file changed
+22 -15
+22 -15
View File
@@ -483,6 +483,9 @@ def voice_preview(string):
return f"[{params['branding']}Server] Audio generation failed. Status: {generate_response.get('status')}" return f"[{params['branding']}Server] Audio generation failed. Status: {generate_response.get('status')}"
def replace_asterisk(match):
return match.group(0) + '&quot;<*'
################################# #################################
#### TTS STANDARD GENERATION #### #### TTS STANDARD GENERATION ####
################################# #################################
@@ -491,6 +494,7 @@ def output_modifier(string, state):
if not params["activate"]: if not params["activate"]:
return string return string
original_string = string original_string = string
print("ORGINAL STRING: ", original_string)
cleaned_string = before_audio_generation(string, params) cleaned_string = before_audio_generation(string, params)
if cleaned_string is None: if cleaned_string is None:
return return
@@ -508,25 +512,28 @@ def output_modifier(string, state):
.replace("***", "*") .replace("***", "*")
.replace("**", "*") .replace("**", "*")
.replace("\n\n", "\n") .replace("\n\n", "\n")
.replace("\n", "")
) )
# Clean up two asterisks (narrators) being made between a newline, making it one sentence.
processed_string = re.sub(r'\.\*\n\*', '. ', processed_string) processed_string = re.sub(r'\.\*\n\*', '. ', processed_string)
# Clean up a few other bits. processed_string = (processed_string .replace('&quot;\n\n*', '&quot;<*'))
processed_string = ( processed_string = (processed_string .replace('&quot;\n', '< '))
processed_string processed_string = (processed_string .replace("&#x27;", "'"))
.replace("&#x27;", "'") processed_string = (processed_string .replace("\n", " "))
.replace("\n", " ") processed_string = (processed_string .replace('&quot;', '&quot;<'))
# Add special characters to the quote so that we can use it to identify things later after its been split processed_string = (processed_string .replace('"', '&quot;<'))
.replace('&quot;', '&quot;<') #pattern = re.compile(r'(?<=[a-zA-Z!])&quot;<(?=[a-zA-Z])')
# Capture new conversations which wont have things like &quote in them pattern = re.compile(r'(?<=[a-zA-Z!?\.])&quot;<(?=[a-zA-Z])')
.replace('"', '&quot;<') processed_string = pattern.sub('&quot; ', processed_string)
) pattern = re.compile(r'(?<=[a-zA-Z])\*(?=[a-zA-Z])')
#capturing another outlier in inital character paragraph processed_string = pattern.sub('*&quot;', processed_string)
#print("processed string 1 is:", processed_string)
processed_string = processed_string.replace('&quot;<. *', '&quot;< *"') processed_string = processed_string.replace('&quot;<. *', '&quot;< *"')
processed_string = processed_string.replace('< *"', '< *') processed_string = processed_string.replace('< *"', '< *')
processed_string = processed_string.replace('. *', '< *') processed_string = processed_string.replace('. *', '< *')
#print("processed string 2 is:", processed_string) processed_string = processed_string.replace('! *', '&quot;< *')
processed_string = processed_string.replace('? *', '< *')
processed_string = processed_string.replace('* ', '* &quot;<')
processed_string = processed_string.replace('*. ', '* &quot;<')
processed_string = re.sub(r'\*(?=[a-zA-Z])', replace_asterisk, processed_string)
# Set up a tracking of the individual wav files. # Set up a tracking of the individual wav files.
audio_files_all_paragraphs = [] audio_files_all_paragraphs = []
# Split the line using &quot; and ".* " (so end of sentences, leaving special characters added to the start of all OTHER sentences, bar possibly the first one if its starting with a * # Split the line using &quot; and ".* " (so end of sentences, leaving special characters added to the start of all OTHER sentences, bar possibly the first one if its starting with a *
@@ -534,7 +541,7 @@ def output_modifier(string, state):
audio_files_paragraph = [] audio_files_paragraph = []
for i, part in enumerate(parts): for i, part in enumerate(parts):
# Skip parts that are too short # Skip parts that are too short
if len(part.strip()) <= 1: if len(part.strip()) <= 3:
continue continue
# Figure out which type of line it is, then replace characters as necessary to avoid TTS trying to pronunce them, htmlunescape after. # Figure out which type of line it is, then replace characters as necessary to avoid TTS trying to pronunce them, htmlunescape after.
# Character will always be a < with a letter immediately after it # Character will always be a < with a letter immediately after it