Patch: descript.py
Changes made: 1. Created a new class called DecodeTranscriptNode. 2. Added class method INPUT_TYPES() to define the input types for the class. 3. Defined class variables RETURN_TYPES, RETURN_NAMES, and OUTPUT_NODE for the class. 4. Implemented the func() method to decode a descript transcript file and return the speakers, durations, and paragraphs as lists of strings. 5. Added the ETK_descript_base decorator to the class. Impact: The new DecodeTranscriptNode class allows for decoding descript transcript files and extracting the speakers, durations, and paragraphs from the file. Note: The patch also includes some import statements and post-processing calculations for the durations.
This commit is contained in:
+88
@@ -0,0 +1,88 @@
|
||||
import copy
|
||||
|
||||
NODE_CLASS_MAPPINGS = {}
|
||||
|
||||
|
||||
def ETK_descript_base(cls):
|
||||
cls.FUNCTION = "func"
|
||||
cls.CATEGORY = "ETK/Descript"
|
||||
NODE_CLASS_MAPPINGS[cls.__name__] = cls
|
||||
return cls
|
||||
|
||||
@ETK_descript_base
|
||||
class DecodeTranscriptNode:
|
||||
"""
|
||||
Decode one of descript's transcript formatted files
|
||||
String input is the files contents
|
||||
output is 3 lists of strings (speaker,duration,paragraph,)
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"string": ("STRING", {"multiline": True,
|
||||
"default": ""
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("LIST","LIST","LIST")
|
||||
RETURN_NAMES = ("speakers","durations","paragraphs")
|
||||
OUTPUT_NODE = True
|
||||
|
||||
def func(self, string):
|
||||
"""
|
||||
input is like:
|
||||
[00:00:00] jackie: Let's talk about a
|
||||
|
||||
[00:00:01] jackie: thing
|
||||
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
paras = string.split("\n\n")
|
||||
speakers = []
|
||||
durations = []
|
||||
paragraphs = []
|
||||
|
||||
for para in paras:
|
||||
if para.strip() == "":
|
||||
continue
|
||||
# first find the first ] and split on that
|
||||
part1 = para.find("]")
|
||||
time_part = para[:part1+1]
|
||||
remainder = para[part1+1:]
|
||||
|
||||
# now find first : in the remainder
|
||||
part2 = remainder.find(":")
|
||||
speaker_part = remainder[:part2+1].replace(":","").strip()
|
||||
paragraph_part = remainder[part2+1:]
|
||||
speakers.append(speaker_part.strip())
|
||||
|
||||
# now just remove [ and ] from time_part
|
||||
time_part = time_part.replace("[","").replace("]","").strip()
|
||||
|
||||
#split it on :
|
||||
time_part = time_part.split(":")
|
||||
|
||||
# now convert to seconds
|
||||
time_part = int(time_part[0])*60*60 + int(time_part[1])*60 + int(time_part[2])
|
||||
|
||||
# save here for post-processing later
|
||||
durations.append(time_part)
|
||||
|
||||
paragraphs.append(paragraph_part.strip())
|
||||
|
||||
import copy
|
||||
start_seconds = copy.copy(durations)
|
||||
durations=[]
|
||||
for i in range(len(start_seconds)-1):
|
||||
durations.append(start_seconds[i+1] - start_seconds[i])
|
||||
# now append the last value
|
||||
durations.append(int(sum(durations)/len(durations)))
|
||||
|
||||
return (speakers,durations,paragraphs,)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user