Files
TashaSkyUp-EternalKernelPyt…/modules/xttscli.py
T
Tasha Upchurch d9170f804b New Features: Added nodes for advanced video and audio processing
Key updates:

Added AddFramesToVideoFolder node to add frames to a video folder
Introduced VideoFolderProvider and VideoDefinitionProvider nodes to manage video folders and video definitions
Added FadeToInVideoFolder node for fading between frames in a video folder
Implemented ListedSVDConditioning node for applying SVD conditioning to a list of parameters
Added VideoFolderFFMPEGVideoInterpolate node to interpolate frames in a video folder using FFmpeg
Introduced AudioFolderProvider and AudioDefinitionProvider nodes for managing audio folders and definitions
Added AddAudioToAudioFolder and AddSilenceToAudioFolder nodes for adding audio files and silence to audio folders
Implemented GetAudioFilesLengthsFromAudioFolder node to retrieve lengths of audio files in a folder
Added AudioFolderRenderAudio node to join audio files in an audio folder
Introduced GenerateMusic node for generating music from descriptions using the AudioCraft library
Added XttsNode for text-to-speech conversion using the XTTS library
Implemented AdjustAudioVolumeForFiles node to adjust volume for a list of audio files
The changes also include the addition of LiteLLM nodes for text generation:

Added FuncAnysToText node that runs Python code with multiple input types and outputs a string
Introduced FuncAnysToLatent node for running code that outputs a latent representation
Added FuncAnysToString node for executing code with various inputs and producing a string output
Implemented FuncAnysToList node to run code that takes different input types and returns a list
Added FuncAnysToCond node for running code with multiple inputs and generating a conditioning output

These new nodes expand the capabilities for video and audio processing, allowing more advanced manipulations and generation of video and audio content within the graph.
2024-04-15 13:29:31 -04:00

94 lines
2.5 KiB
Python

import argparse
import torch.multiprocessing as mp
from concurrent.futures import ProcessPoolExecutor, as_completed
def generate_xtts_for_text(text, file, lang, speaker):
from TTS.api import TTS
import torch
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")
tts.tts_to_file(
text=text,
speaker_wav=speaker,
language=lang,
file_path=file,
# emotion="angry", # doesnt do anything as far as i can tell with xtts2
)
def generate_xtts(**kwargs):
import torch
import ast
import uuid
from concurrent.futures import ProcessPoolExecutor, as_completed
torch.cuda.empty_cache()
text = kwargs.get('text')
folder = kwargs.get('folder', '.')
lang = kwargs.get('lang', 'en')
speaker = kwargs.get('speaker', '')
try:
texts = ast.literal_eval(text)
except SyntaxError:
texts = [text]
o_files = []
batch_size = 3
with ProcessPoolExecutor(max_workers=batch_size) as executor:
futures = []
for i, text in enumerate(texts):
ii = str(i).zfill(1 + len(str(1 + len(texts))))
file_to_use = f"{folder}/tts_{ii}_{str(uuid.uuid4())}.wav"
future = executor.submit(generate_xtts_for_text, text, file_to_use, lang, speaker)
futures.append((future, file_to_use))
for future, file_to_use in futures:
future.result()
o_files.append(file_to_use)
torch.cuda.empty_cache()
return (o_files[0], o_files,)
# def generate_xtts_for_text_advanced(text, file, lang, speaker):
# from TTS.api import TTS
# import torch
#
# # Create a SharedMemoryManager
# manager = mp.Manager()
# # Create a shared list to store the result
# result = manager.list()
# model = manager.model()
#
#
# # also we want to SHARE the TTS model
# something = manager.
def main():
parser = argparse.ArgumentParser(description='Generate from given text.')
parser.add_argument('--text', help='Text to generate for')
parser.add_argument('--folder', type=str, default='.', help='output folder')
parser.add_argument('--lang', type=str, default='en')
parser.add_argument('--speaker', type=str, default='', help='Speaker wav use for generation')
args = parser.parse_args()
kwargs = vars(args)
print(f"Generating with the following arguments: {kwargs}")
generated_files = generate_xtts(**kwargs)
print(f"Generated files: {generated_files}")
if __name__ == "__main__":
main()