Spaces:
Running
on
Zero
Running
on
Zero
Enhance processing metrics in TTSModelV1 by calculating total audio duration and processing time per chunk
Browse files- tts_model_v1.py +22 -14
tts_model_v1.py
CHANGED
@@ -83,27 +83,35 @@ class TTSModelV1:
|
|
83 |
)
|
84 |
|
85 |
# Process chunks
|
|
|
|
|
|
|
86 |
for i, (gs, ps, audio) in enumerate(generator):
|
87 |
-
|
|
|
88 |
audio_chunks.append(audio)
|
89 |
|
90 |
# Calculate metrics
|
91 |
-
chunk_time = time.time() - chunk_start
|
92 |
chunk_tokens = len(gs)
|
93 |
total_tokens += chunk_tokens
|
94 |
|
|
|
|
|
|
|
|
|
95 |
# Calculate speed metrics
|
96 |
-
|
97 |
-
rtf =
|
98 |
-
chunk_tokens_per_sec = chunk_tokens / chunk_time
|
99 |
|
100 |
-
chunk_times.append(
|
101 |
-
chunk_sizes.append(
|
102 |
|
103 |
-
print(f"Chunk {i+1}
|
104 |
-
print(f"
|
105 |
-
print(f"
|
106 |
-
print(f"{
|
|
|
|
|
107 |
|
108 |
# Update progress
|
109 |
if progress_callback and progress_state:
|
@@ -116,14 +124,14 @@ class TTSModelV1:
|
|
116 |
progress_state["chunk_times"] = []
|
117 |
|
118 |
# Update progress state
|
119 |
-
progress_state["tokens_per_sec"].append(
|
120 |
progress_state["rtf"].append(rtf)
|
121 |
-
progress_state["chunk_times"].append(
|
122 |
|
123 |
progress_callback(
|
124 |
i + 1,
|
125 |
-1, # Let UI handle total chunks
|
126 |
-
|
127 |
rtf,
|
128 |
progress_state,
|
129 |
start_time,
|
|
|
83 |
)
|
84 |
|
85 |
# Process chunks
|
86 |
+
total_duration = 0 # Total audio duration in seconds
|
87 |
+
total_process_time = 0 # Total processing time in seconds
|
88 |
+
|
89 |
for i, (gs, ps, audio) in enumerate(generator):
|
90 |
+
chunk_process_time = time.time() - start_time - total_process_time
|
91 |
+
total_process_time += chunk_process_time
|
92 |
audio_chunks.append(audio)
|
93 |
|
94 |
# Calculate metrics
|
|
|
95 |
chunk_tokens = len(gs)
|
96 |
total_tokens += chunk_tokens
|
97 |
|
98 |
+
# Calculate audio duration
|
99 |
+
chunk_duration = len(audio) / 24000 # Convert samples to seconds
|
100 |
+
total_duration += chunk_duration
|
101 |
+
|
102 |
# Calculate speed metrics
|
103 |
+
tokens_per_sec = chunk_tokens / chunk_duration # Tokens per second of audio
|
104 |
+
rtf = chunk_process_time / chunk_duration # Real-time factor
|
|
|
105 |
|
106 |
+
chunk_times.append(chunk_process_time)
|
107 |
+
chunk_sizes.append(chunk_tokens)
|
108 |
|
109 |
+
print(f"Chunk {i+1}:")
|
110 |
+
print(f" Process time: {chunk_process_time:.2f}s")
|
111 |
+
print(f" Audio duration: {chunk_duration:.2f}s")
|
112 |
+
print(f" Tokens/sec: {tokens_per_sec:.1f}")
|
113 |
+
print(f" Real-time factor: {rtf:.3f}")
|
114 |
+
print(f" Speed: {(1/rtf):.1f}x real-time")
|
115 |
|
116 |
# Update progress
|
117 |
if progress_callback and progress_state:
|
|
|
124 |
progress_state["chunk_times"] = []
|
125 |
|
126 |
# Update progress state
|
127 |
+
progress_state["tokens_per_sec"].append(tokens_per_sec)
|
128 |
progress_state["rtf"].append(rtf)
|
129 |
+
progress_state["chunk_times"].append(chunk_process_time)
|
130 |
|
131 |
progress_callback(
|
132 |
i + 1,
|
133 |
-1, # Let UI handle total chunks
|
134 |
+
tokens_per_sec,
|
135 |
rtf,
|
136 |
progress_state,
|
137 |
start_time,
|