Merge pull request #13 from danielwburch/refactor_output_filename_2
Refactor output file naming in script.py
This commit is contained in:
1 file changed
+9
-17
@@ -552,15 +552,10 @@ def output_modifier(string, state):
|
|||||||
else:
|
else:
|
||||||
cleaned_part = html.unescape(part.replace('< ', '').replace('< ', '').replace('< ', ''))
|
cleaned_part = html.unescape(part.replace('< ', '').replace('< ', '').replace('< ', ''))
|
||||||
voice_to_use = params["narrator_voice"]
|
voice_to_use = params["narrator_voice"]
|
||||||
# Check if character name exists and if not, just call it TTSOUT_
|
|
||||||
if "character_menu" in state:
|
|
||||||
output_file = Path(f'{params["output_folder_wav"]}/{state["character_menu"]}_{int(time.time())}_{i}.wav')
|
|
||||||
else:
|
|
||||||
output_file = Path(f'{params["output_folder_wav"]}/TTSOUT_{int(time.time())}_{i}.wav')
|
|
||||||
# Generate that TTS and output to a file
|
# Generate that TTS and output to a file
|
||||||
output_file_str = output_file.as_posix()
|
output_filename = get_output_filename(state)
|
||||||
generate_response = send_generate_request(
|
generate_response = send_generate_request(
|
||||||
cleaned_part, voice_to_use, language_code, output_file_str
|
cleaned_part, voice_to_use, language_code, output_filename
|
||||||
)
|
)
|
||||||
audio_path = generate_response.get("data", {}).get("audio_path")
|
audio_path = generate_response.get("data", {}).get("audio_path")
|
||||||
audio_files_paragraph.append(audio_path)
|
audio_files_paragraph.append(audio_path)
|
||||||
@@ -581,14 +576,9 @@ def output_modifier(string, state):
|
|||||||
)
|
)
|
||||||
cleaned_part = html.unescape(processed_string)
|
cleaned_part = html.unescape(processed_string)
|
||||||
# Process the part and give it a non-character name if being used vai API or standalone.
|
# Process the part and give it a non-character name if being used vai API or standalone.
|
||||||
if "character_menu" in state:
|
output_filename = get_output_filename(state)
|
||||||
output_file = Path(f'{params["output_folder_wav"]}/{state["character_menu"]}_{int(time.time())}.wav')
|
|
||||||
else:
|
|
||||||
output_file = Path(f'{params["output_folder_wav"]}/TTSOUT_{int(time.time())}.wav')
|
|
||||||
output_file_str = output_file.as_posix()
|
|
||||||
output_file = get_output_filename(state)
|
|
||||||
generate_response = send_generate_request(
|
generate_response = send_generate_request(
|
||||||
cleaned_part, params["voice"], language_code, output_file_str
|
cleaned_part, params["voice"], language_code, output_filename
|
||||||
)
|
)
|
||||||
audio_path = generate_response.get("data", {}).get("audio_path")
|
audio_path = generate_response.get("data", {}).get("audio_path")
|
||||||
final_output_file = audio_path
|
final_output_file = audio_path
|
||||||
@@ -628,9 +618,11 @@ def output_modifier(string, state):
|
|||||||
|
|
||||||
|
|
||||||
def get_output_filename(state):
|
def get_output_filename(state):
|
||||||
return Path(
|
# Check if character name exists and if not, just call it TTSOUT_
|
||||||
f'{params["output_folder_wav"]}/{state["character_menu"]}_{str(uuid.uuid4())[:8]}.wav'
|
if "character_menu" in state:
|
||||||
).as_posix()
|
return Path(f'{params["output_folder_wav"]}/{state["character_menu"]}_{int(time.time())}.wav').as_posix()
|
||||||
|
else:
|
||||||
|
return Path(f'{params["output_folder_wav"]}/TTSOUT_{int(time.time())}.wav').as_posix()
|
||||||
|
|
||||||
|
|
||||||
###############################################
|
###############################################
|
||||||
|
|||||||
Reference in new issue
Block a user