|
|
|
|
|
from kokoro import KPipeline |
|
from IPython.display import display, Audio |
|
import soundfile as sf |
|
import torch |
|
import numpy as np |
|
from scipy import signal |
|
import os |
|
import json |
|
from pathlib import Path |
|
from tqdm import tqdm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import random |
|
random.seed(42) |
|
|
|
|
|
def get_random_rir_generator(simulated_rirs_dict): |
|
"""Generator that yields random RIR file paths from the simulated_rirs_dict""" |
|
rir_paths = list(simulated_rirs_dict.keys()) |
|
while True: |
|
yield random.choice(rir_paths) |
|
|
|
def get_random_white_noise_generator(white_noise_dict): |
|
"""Generator that yields random white noise file paths from the white_noise_dict""" |
|
white_noise_paths = list(white_noise_dict.keys()) |
|
while True: |
|
yield random.choice(white_noise_paths) |
|
|
|
|
|
def load_manifest_file(manifest_path): |
|
""" |
|
Load a JSONL manifest file into a dictionary. |
|
|
|
Args: |
|
manifest_path (str): Path to the JSONL manifest file |
|
|
|
Returns: |
|
dict: Dictionary with audio filepath as key and metadata as value |
|
""" |
|
manifest_dict = {} |
|
|
|
try: |
|
with open(manifest_path, 'r') as f: |
|
for line_num, line in enumerate(f, 1): |
|
line = line.strip() |
|
if line: |
|
try: |
|
entry = json.loads(line) |
|
audio_filepath = entry.get('audio_filepath') |
|
if audio_filepath: |
|
manifest_dict[audio_filepath] = entry |
|
else: |
|
print(f"Warning: Line {line_num} missing audio_filepath") |
|
except json.JSONDecodeError as e: |
|
print(f"Warning: Invalid JSON on line {line_num}: {e}") |
|
continue |
|
|
|
print(f"Successfully loaded {len(manifest_dict)} entries from {manifest_path}") |
|
return manifest_dict |
|
|
|
except FileNotFoundError: |
|
print(f"Error: Manifest file not found: {manifest_path}") |
|
return {} |
|
except Exception as e: |
|
print(f"Error loading manifest file {manifest_path}: {e}") |
|
return {} |
|
|
|
def load_rirs_manifests(simulated_rirs_path="/disk_a_nvd/datasets/RIRS_NOISES/simulated_rirs.json", |
|
white_noise_path="/disk_a_nvd/datasets/RIRS_NOISES/white_noise.json" |
|
): |
|
""" |
|
Load both RIRS_NOISES manifest files into dictionaries. |
|
|
|
Args: |
|
simulated_rirs_path (str): Path to the simulated RIRs manifest file |
|
white_noise_path (str): Path to the white noise manifest file |
|
|
|
Returns: |
|
tuple: (simulated_rirs_dict, white_noise_dict) |
|
""" |
|
simulated_rirs_dict = load_manifest_file(simulated_rirs_path) |
|
white_noise_dict = load_manifest_file(white_noise_path) |
|
|
|
return simulated_rirs_dict, white_noise_dict |
|
|
|
def apply_perturb(input_wav_file_path, rir_wav_path, noise_wav_path, noise_scale_factor=3.0, output_sr=16000): |
|
""" |
|
Apply Room Impulse Response (RIR) and optionally noise to an audio file. |
|
|
|
Args: |
|
input_wav_file_path (str): Path to the input audio file |
|
rir_wav_path (str): Path to the RIR file |
|
noise_wav_path (str, optional): Path to the noise file |
|
|
|
Returns: |
|
str: Path to the output file with RIR and noise applied |
|
""" |
|
|
|
input_audio, input_sr = sf.read(input_wav_file_path) |
|
if len(input_audio.shape) > 1: |
|
input_audio = input_audio[:, 0] |
|
|
|
|
|
rir_audio, rir_sr = sf.read(rir_wav_path) |
|
if len(rir_audio.shape) > 1: |
|
rir_audio = rir_audio[:, 0] |
|
|
|
|
|
if input_sr != rir_sr: |
|
print(f"Warning: Sample rate mismatch. Input: {input_sr}Hz, RIR: {rir_sr}Hz") |
|
|
|
if rir_sr != input_sr: |
|
|
|
rir_audio = signal.resample(rir_audio, int(len(rir_audio) * input_sr / rir_sr)) |
|
|
|
|
|
output_audio = signal.convolve(input_audio, rir_audio, mode='full') |
|
|
|
|
|
if noise_wav_path is not None: |
|
try: |
|
|
|
noise_audio, noise_sr = sf.read(noise_wav_path) |
|
if len(noise_audio.shape) > 1: |
|
noise_audio = noise_audio[:, 0] |
|
|
|
|
|
if noise_sr != input_sr: |
|
noise_audio = signal.resample(noise_audio, int(len(noise_audio) * input_sr / noise_sr)) |
|
|
|
|
|
if len(noise_audio) < len(output_audio): |
|
|
|
repeats_needed = int(np.ceil(len(output_audio) / len(noise_audio))) |
|
noise_audio = np.tile(noise_audio, repeats_needed) |
|
|
|
|
|
noise_audio = noise_audio[:len(output_audio)] |
|
|
|
|
|
noise_scale = noise_scale_factor * np.max(np.abs(output_audio)) |
|
output_audio += noise_scale * noise_audio |
|
|
|
|
|
except Exception as e: |
|
raise SyntaxError(f"Error: Could not apply noise from {noise_wav_path}: {e}") |
|
|
|
|
|
max_val = np.max(np.abs(output_audio)) |
|
if max_val > 0: |
|
output_audio = output_audio / max_val * 0.95 |
|
|
|
|
|
input_path = Path(input_wav_file_path) |
|
rir_path = Path(rir_wav_path) |
|
rir_name = rir_path.stem |
|
|
|
if noise_wav_path is not None: |
|
noise_path = Path(noise_wav_path) |
|
noise_name = "_".join(noise_path.stem.split("_")[-2:]) |
|
output_filename = f"{input_path.stem}_R_{rir_name}_N_{noise_name}{input_path.suffix}" |
|
else: |
|
output_filename = f"{input_path.stem}_R_{rir_name}{input_path.suffix}" |
|
|
|
|
|
|
|
output_path = f"{input_path.parent}/{output_filename}" |
|
output_path = os.path.abspath(output_path) |
|
|
|
|
|
|
|
output_audio = signal.resample(output_audio, int(len(output_audio) * output_sr / input_sr)) |
|
sf.write(str(output_path), output_audio, output_sr) |
|
|
|
|
|
|
|
return output_audio, str(output_path) |
|
|
|
|
|
def concat_with_fo_fi(audio1, audio2, sr=16000, transition_time=0.2): |
|
""" |
|
Concatenate two audio arrays with fade out on the first and fade in on the second. |
|
|
|
Args: |
|
audio1 (np.array): First audio array |
|
audio2 (np.array): Second audio array |
|
sr (int): Sample rate |
|
transition_time (float): Transition time in seconds |
|
|
|
Returns: |
|
np.array: Concatenated audio with smooth transition |
|
""" |
|
|
|
transition_samples = int(transition_time * sr) |
|
|
|
|
|
transition_samples = min(transition_samples, len(audio1), len(audio2)) |
|
|
|
|
|
fade_out = np.linspace(1.0, 0.0, transition_samples) |
|
audio1_faded = audio1.copy() |
|
audio1_faded[-transition_samples:] *= fade_out |
|
|
|
|
|
fade_in = np.linspace(0.0, 1.0, transition_samples) |
|
audio2_faded = audio2.copy() |
|
audio2_faded[:transition_samples] *= fade_in |
|
|
|
|
|
|
|
audio1_part = audio1_faded[:-transition_samples] |
|
audio2_part = audio2_faded[transition_samples:] |
|
|
|
|
|
concatenated = np.concatenate([audio1_part, audio2_part]) |
|
|
|
return concatenated |
|
|
|
|
|
def get_manifest_entry(audio_filepath, text, label="infer", num_speakers=1, rttm_filepath=None, uem_filepath=None, ctm_filepath=None): |
|
|
|
|
|
audio_duration = sf.SoundFile(audio_filepath).frames / sf.SoundFile(audio_filepath).samplerate |
|
duration_in_seconds = round(audio_duration, 2) |
|
|
|
|
|
|
|
audio_filepath = os.path.abspath(audio_filepath) |
|
rttm_filepath = os.path.abspath(rttm_filepath) |
|
|
|
return { |
|
"audio_filepath": audio_filepath, |
|
"offset": 0, |
|
"duration": duration_in_seconds, |
|
"label": label, |
|
"text": text, |
|
"num_speakers": num_speakers, |
|
"rttm_filepath": rttm_filepath, |
|
"uem_filepath": uem_filepath, |
|
"ctm_filepath": ctm_filepath, |
|
"source_lang": "en", |
|
"target_lang": "en", |
|
"pnc": "no", |
|
"timestamp": "no", |
|
} |
|
|
|
def make_single_speaker_rttm(uniq_id, audio_filepath, rttm_filepath, speaker_name): |
|
""" |
|
SPEAKER {uniq_id} 0 {duration:.3f} <NA> <NA> {speaker_name} <NA> <NA> |
|
""" |
|
|
|
audio, sr = sf.read(audio_filepath) |
|
duration = len(audio) / sr |
|
|
|
|
|
with open(rttm_filepath, 'w') as f: |
|
f.write(f"SPEAKER {uniq_id} 0.0 {duration:.3f} <NA> <NA> {speaker_name} <NA> <NA>\n") |
|
|
|
def make_two_speaker_rttm(uniq_id, audio_filepath_A, audio_filepath_B, rttm_filepath, speaker_A, speaker_B): |
|
""" |
|
# SPEAKER iapb 0 0 3.26 <NA> <NA> speaker_A <NA> <NA> |
|
# SPEAKER iapb 0 3.26 0.42 <NA> <NA> speaker_B <NA> <NA> |
|
""" |
|
|
|
audio_A, sr = sf.read(audio_filepath_A) |
|
duration_A = len(audio_A) / sr |
|
|
|
audio_B, sr = sf.read(audio_filepath_B) |
|
duration_B = len(audio_B) / sr |
|
|
|
|
|
with open(rttm_filepath, 'w') as f: |
|
|
|
f.write(f"SPEAKER {uniq_id} 1 0.0 {duration_A:.3f} <NA> <NA> {speaker_A} <NA> <NA>\n") |
|
f.write(f"SPEAKER {uniq_id} 1 {duration_A:.3f} {duration_B:.3f} <NA> <NA> {speaker_B} <NA> <NA>\n") |
|
|
|
|
|
pipeline = KPipeline(lang_code='a') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text_list_A = [ |
|
"She sells sea shells by the seashore while subtly shifting sapphire souvenirs.", |
|
"The anthropologist's anecdote about antediluvian artifacts was astonishingly ambiguous.", |
|
"I scream, you scream, we all scream for ice cream, especially when it's free.", |
|
"Their heir apparently inherited an eerily empty estate.", |
|
"Can you can a can as a canner can can a can?", |
|
"The lead violinist led the lead singer through a leaden performance.", |
|
"Fred fed Ted bread, and Ted fed Fred bread.", |
|
"I thought a thought but the thought I thought wasn't the thought I thought I thought.", |
|
"How can a clam cram in a clean cream can?", |
|
"Six slippery snails slid slowly seaward.", |
|
"I slit the sheet, the sheet I slit, and on the slitted sheet I sit.", |
|
"Lesser leather never weathered wetter weather better." |
|
] |
|
text_list_B = text_list_A[::-1] |
|
|
|
|
|
|
|
speaker_list = [ |
|
|
|
"af_heart", |
|
"af_bella", |
|
"af_nicole", |
|
"af_aoede", |
|
"af_kore", |
|
"af_sarah", |
|
|
|
"bf_emma", |
|
"bf_isabella", |
|
|
|
"am_fenrir", |
|
"am_michael", |
|
"am_puck", |
|
"am_echo", |
|
"am_eric", |
|
"am_liam", |
|
|
|
"bm_fable", |
|
"bm_george", |
|
] |
|
|
|
|
|
|
|
simulated_rir_manifest_path = "/disk_a_nvd/datasets/RIRS_NOISES/simulated_rirs.json" |
|
white_noise_manifest_path = "/disk_a_nvd/datasets/RIRS_NOISES/white_noise.json" |
|
|
|
simulated_rirs_dict, white_noise_dict = load_rirs_manifests(simulated_rir_manifest_path, white_noise_manifest_path) |
|
|
|
|
|
rir_generator = get_random_rir_generator(simulated_rirs_dict) |
|
white_noise_generator = get_random_white_noise_generator(white_noise_dict) |
|
|
|
speech_speed = 1.3 |
|
|
|
base_folder_name = "utt_samples" |
|
shift_left = 15 |
|
speaker_list_A = speaker_list |
|
speaker_list_B = speaker_list_A[shift_left:] + speaker_list_A[:shift_left] |
|
|
|
|
|
matched_speaker_mode = False |
|
folder_name = base_folder_name + "_matched" if matched_speaker_mode else base_folder_name + "_unmatched" |
|
|
|
|
|
os.makedirs(folder_name, exist_ok=True) |
|
|
|
if matched_speaker_mode: |
|
num_speakers = 1 |
|
else: |
|
num_speakers = 2 |
|
|
|
|
|
indiv_text_manifest_clean = [] |
|
indiv_text_manifest_clean_perturbed = [] |
|
indiv_text_manifest_perturbed_clean = [] |
|
indiv_text_manifest_perturbed = [] |
|
pair_text_manifest_Ac_Bc = [] |
|
pair_text_manifest_Ac_Bp = [] |
|
pair_text_manifest_Ap_Bc = [] |
|
pair_text_manifest_Ap_Bp = [] |
|
|
|
count = 0 |
|
total_speakers = len(speaker_list_A) |
|
for speaker_A, speaker_B in tqdm(zip(speaker_list_A, speaker_list_B), total=total_speakers, desc="Processing speakers"): |
|
|
|
|
|
|
|
|
|
count += 1 |
|
|
|
if matched_speaker_mode: |
|
speaker_B = speaker_A |
|
|
|
generator_A = pipeline( |
|
text_list_A, voice=speaker_A, |
|
speed=speech_speed, split_pattern=r'\n+' |
|
) |
|
generator_B = pipeline( |
|
text_list_B, voice=speaker_B, |
|
speed=speech_speed, split_pattern=r'\n+' |
|
) |
|
text_data_size = len(text_list_A) |
|
text_data_size_B = len(text_list_B) |
|
assert text_data_size == text_data_size_B, "Text data size mismatch" |
|
|
|
for idx, ((gs_text_A, ps_A, audio_A), (gs_text_B, ps_B, audio_B)) in tqdm(enumerate(zip(generator_A, generator_B)), total=text_data_size, desc=f"Processing {speaker_A} vs {speaker_B}", leave=False): |
|
|
|
|
|
A_idx = idx |
|
B_idx = str(text_data_size - A_idx - 1).zfill(2) |
|
A_idx = str(A_idx).zfill(2) |
|
|
|
|
|
rir_wav_path = next(rir_generator) |
|
noise_wav_path = next(white_noise_generator) |
|
|
|
|
|
|
|
|
|
sub_folder_name = f"A_text{A_idx}_{speaker_A}_B_text{B_idx}_{speaker_B}" |
|
|
|
os.makedirs(f"{folder_name}/{sub_folder_name}", exist_ok=True) |
|
|
|
|
|
uniq_id_a = f"A_text{A_idx}_{speaker_A}" |
|
original_filename_A = f'{folder_name}/{sub_folder_name}/{uniq_id_a}.wav' |
|
|
|
audio_A_16k = signal.resample(audio_A, int(len(audio_A) * 16000 / 24000)) |
|
sf.write(original_filename_A, audio_A_16k, 16000) |
|
|
|
|
|
try: |
|
perturbed_audio_A_16k, perturbed_audio_A_16k_path = apply_perturb(original_filename_A, rir_wav_path, noise_wav_path) |
|
except Exception as e: |
|
print(f"Error applying perturbation to {original_filename_A}: {e}") |
|
|
|
|
|
uniq_id_b = f"B_text{B_idx}_{speaker_B}" |
|
original_filename_B = f'{folder_name}/{sub_folder_name}/{uniq_id_b}.wav' |
|
audio_B_16k = signal.resample(audio_B, int(len(audio_B) * 16000 / 24000)) |
|
sf.write(original_filename_B, audio_B_16k, 16000) |
|
|
|
|
|
try: |
|
perturbed_audio_B_16k, perturbed_audio_B_16k_path = apply_perturb(original_filename_B, rir_wav_path, noise_wav_path) |
|
except Exception as e: |
|
print(f"Error applying perturbation to {original_filename_B}: {e}") |
|
|
|
pair_gt_text = f"{gs_text_A} {gs_text_B}" |
|
uniq_id_pair = f"{uniq_id_a}_{uniq_id_b}" |
|
uniq_id_pair_Ac_Bc = f"{uniq_id_a}_Ac_Bc" |
|
uniq_id_pair_Ac_Bp = f"{uniq_id_a}_Ac_Bp" |
|
uniq_id_pair_Ap_Bc = f"{uniq_id_a}_Ap_Bc" |
|
uniq_id_pair_Ap_Bp = f"{uniq_id_a}_Ap_Bp" |
|
|
|
|
|
|
|
uniq_id_a_perturbed = Path(perturbed_audio_A_16k_path).stem |
|
uniq_id_b_perturbed = Path(perturbed_audio_B_16k_path).stem |
|
|
|
rttm_path_A = f"{folder_name}/{sub_folder_name}/{uniq_id_a}.rttm" |
|
rttm_path_B = f"{folder_name}/{sub_folder_name}/{uniq_id_b}.rttm" |
|
rttm_path_A_perturbed = f"{folder_name}/{sub_folder_name}/{uniq_id_a_perturbed}.rttm" |
|
rttm_path_B_perturbed = f"{folder_name}/{sub_folder_name}/{uniq_id_b_perturbed}.rttm" |
|
|
|
make_single_speaker_rttm(uniq_id_a, original_filename_A, rttm_path_A, speaker_A) |
|
make_single_speaker_rttm(uniq_id_b, original_filename_B, rttm_path_B, speaker_B) |
|
make_single_speaker_rttm(uniq_id_a_perturbed, perturbed_audio_A_16k_path, rttm_path_A_perturbed, speaker_A) |
|
make_single_speaker_rttm(uniq_id_b_perturbed, perturbed_audio_B_16k_path, rttm_path_B_perturbed, speaker_B) |
|
|
|
rttm_path_pair_Ac_Bc = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ac_Bc.rttm" |
|
rttm_path_pair_Ac_Bp = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ac_Bp.rttm" |
|
rttm_path_pair_Ap_Bc = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ap_Bc.rttm" |
|
rttm_path_pair_Ap_Bp = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ap_Bp.rttm" |
|
|
|
make_two_speaker_rttm(uniq_id_pair_Ac_Bc, original_filename_A, original_filename_B, rttm_path_pair_Ac_Bc, speaker_A, speaker_B) |
|
make_two_speaker_rttm(uniq_id_pair_Ac_Bp, original_filename_A, perturbed_audio_B_16k_path, rttm_path_pair_Ac_Bp, speaker_A, speaker_B) |
|
make_two_speaker_rttm(uniq_id_pair_Ap_Bc, perturbed_audio_A_16k_path, original_filename_B, rttm_path_pair_Ap_Bc, speaker_A, speaker_B) |
|
make_two_speaker_rttm(uniq_id_pair_Ap_Bp, perturbed_audio_A_16k_path, perturbed_audio_B_16k_path, rttm_path_pair_Ap_Bp, speaker_A, speaker_B) |
|
|
|
|
|
Ac_Bc_filename = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ac_Bc.wav" |
|
Ac_Bp_filename = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ac_Bp.wav" |
|
Ap_Bc_filename = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ap_Bc.wav" |
|
Ap_Bp_filename = f"{folder_name}/{sub_folder_name}/{uniq_id_pair}_Ap_Bp.wav" |
|
|
|
|
|
|
|
Ac_Bc_audio = concat_with_fo_fi(audio_A_16k, audio_B_16k) |
|
Ac_Bp_audio = concat_with_fo_fi(audio_A_16k, perturbed_audio_B_16k) |
|
Ap_Bc_audio = concat_with_fo_fi(perturbed_audio_A_16k, audio_B_16k) |
|
Ap_Bp_audio = concat_with_fo_fi(perturbed_audio_A_16k, perturbed_audio_B_16k) |
|
|
|
sf.write(Ac_Bc_filename, Ac_Bc_audio, 16000) |
|
sf.write(Ac_Bp_filename, Ac_Bp_audio, 16000) |
|
sf.write(Ap_Bc_filename, Ap_Bc_audio, 16000) |
|
sf.write(Ap_Bp_filename, Ap_Bp_audio, 16000) |
|
|
|
indiv_text_manifest_clean.append(get_manifest_entry(original_filename_A, text=gs_text_A, num_speakers=1, rttm_filepath=rttm_path_A, uem_filepath=None, ctm_filepath=None)) |
|
indiv_text_manifest_clean.append(get_manifest_entry(original_filename_B, text=gs_text_B, num_speakers=1, rttm_filepath=rttm_path_B, uem_filepath=None, ctm_filepath=None)) |
|
|
|
indiv_text_manifest_clean_perturbed.append(get_manifest_entry(original_filename_A, text=gs_text_A, num_speakers=1, rttm_filepath=rttm_path_A, uem_filepath=None, ctm_filepath=None)) |
|
indiv_text_manifest_clean_perturbed.append(get_manifest_entry(perturbed_audio_B_16k_path, text=gs_text_B, num_speakers=1, rttm_filepath=rttm_path_B_perturbed, uem_filepath=None, ctm_filepath=None)) |
|
|
|
indiv_text_manifest_perturbed_clean.append(get_manifest_entry(perturbed_audio_A_16k_path, text=gs_text_A, num_speakers=1, rttm_filepath=rttm_path_A_perturbed, uem_filepath=None, ctm_filepath=None)) |
|
indiv_text_manifest_perturbed_clean.append(get_manifest_entry(original_filename_B, text=gs_text_B, num_speakers=1, rttm_filepath=rttm_path_B, uem_filepath=None, ctm_filepath=None)) |
|
|
|
indiv_text_manifest_perturbed.append(get_manifest_entry(perturbed_audio_A_16k_path, text=gs_text_A, num_speakers=1, rttm_filepath=rttm_path_A_perturbed, uem_filepath=None, ctm_filepath=None)) |
|
indiv_text_manifest_perturbed.append(get_manifest_entry(perturbed_audio_B_16k_path, text=gs_text_B, num_speakers=1, rttm_filepath=rttm_path_B_perturbed, uem_filepath=None, ctm_filepath=None)) |
|
|
|
pair_text_manifest_Ac_Bc.append(get_manifest_entry(Ac_Bc_filename, text=pair_gt_text, num_speakers=num_speakers, rttm_filepath=rttm_path_pair_Ac_Bc, uem_filepath=None, ctm_filepath=None)) |
|
pair_text_manifest_Ac_Bp.append(get_manifest_entry(Ac_Bp_filename, text=pair_gt_text, num_speakers=num_speakers, rttm_filepath=rttm_path_pair_Ac_Bp, uem_filepath=None, ctm_filepath=None)) |
|
pair_text_manifest_Ap_Bc.append(get_manifest_entry(Ap_Bc_filename, text=pair_gt_text, num_speakers=num_speakers, rttm_filepath=rttm_path_pair_Ap_Bc, uem_filepath=None, ctm_filepath=None)) |
|
pair_text_manifest_Ap_Bp.append(get_manifest_entry(Ap_Bp_filename, text=pair_gt_text, num_speakers=num_speakers, rttm_filepath=rttm_path_pair_Ap_Bp, uem_filepath=None, ctm_filepath=None)) |
|
|
|
|
|
for file in os.listdir(folder_name): |
|
if file.endswith('.json'): |
|
os.remove(os.path.join(folder_name, file)) |
|
|
|
|
|
|
|
with open(f'{folder_name}/indiv_text_manifest_clean.json', 'w') as f: |
|
for entry in indiv_text_manifest_clean: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/indiv_text_manifest_perturbed.json', 'w') as f: |
|
for entry in indiv_text_manifest_perturbed: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/indiv_text_manifest_clean_perturbed.json', 'w') as f: |
|
for entry in indiv_text_manifest_clean_perturbed: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/indiv_text_manifest_perturbed_clean.json', 'w') as f: |
|
for entry in indiv_text_manifest_perturbed_clean: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/pair_text_manifest_Ac_Bc.json', 'w') as f: |
|
for entry in pair_text_manifest_Ac_Bc: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/pair_text_manifest_Ac_Bp.json', 'w') as f: |
|
for entry in pair_text_manifest_Ac_Bp: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/pair_text_manifest_Ap_Bc.json', 'w') as f: |
|
for entry in pair_text_manifest_Ap_Bc: |
|
f.write(json.dumps(entry) + '\n') |
|
with open(f'{folder_name}/pair_text_manifest_Ap_Bp.json', 'w') as f: |
|
for entry in pair_text_manifest_Ap_Bp: |
|
f.write(json.dumps(entry) + '\n') |
|
|