MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTSD / streamer

Function streamer

streamer.py:160–252  ·  view source on GitHub ↗

Process a batch of data items and generate audio, return audio data and metadata

(
    batch_items,
    tokenizer,
    model: AsteroidTTSInstruct,
    spt: XY_Tokenizer,
    device,
    system_prompt,
    use_normalize=False,
    use_tqdm=False,
)

Source from the content-addressed store, hash-verified

158
159
160def streamer(
161 batch_items,
162 tokenizer,
163 model: AsteroidTTSInstruct,
164 spt: XY_Tokenizer,
165 device,
166 system_prompt,
167 use_normalize=False,
168 use_tqdm=False,
169):
170 """Process a batch of data items and generate audio, return audio data and metadata"""
171 # Prepare batch data
172 batch_size = len(batch_items)
173 assert batch_size == 1, "Batch size must be 1 for streaming"
174 texts = []
175 prompts = [system_prompt] * batch_size
176 prompt_audios = []
177 actual_texts_data = [] # Store actual text data used
178
179 # Extract text and audio from each sample
180 for i, item in enumerate(batch_items):
181 # Use new processing function
182 processed_item = process_jsonl_item(item)
183
184 text = processed_item["text"]
185 prompt_text = processed_item["prompt_text"]
186
187 # Merge text, if prompt_text is empty, full_text is just text
188 full_text = prompt_text + text if prompt_text else text
189 original_full_text = full_text # Save original text
190
191 # Apply text normalization based on parameter
192 if use_normalize:
193 full_text = normalize_text(full_text)
194
195 # Replace speaker tags
196 final_text = full_text.replace("[S1]", "<speaker1>").replace(
197 "[S2]", "<speaker2>"
198 )
199 texts.append(final_text)
200
201 # Save actual text information used
202 actual_texts_data.append(
203 {
204 "index": i,
205 "original_text": original_full_text,
206 "normalized_text": (
207 normalize_text(original_full_text) if use_normalize else None
208 ),
209 "final_text": final_text,
210 "use_normalize": use_normalize,
211 }
212 )
213
214 # Get reference audio
215 prompt_audios.append(processed_item["prompt_audio"])
216
217 # Process inputs

Callers 1

mainFunction · 0.85

Calls 7

process_jsonl_itemFunction · 0.90
normalize_textFunction · 0.90
load_audio_dataFunction · 0.90
process_inputsFunction · 0.90
shifting_inputsFunction · 0.90
rpaddingFunction · 0.90

Tested by

no test coverage detected