|
|
import json |
|
|
import random |
|
|
import glob |
|
|
import os |
|
|
|
|
|
|
|
|
prompts = { |
|
|
"sensory": [ |
|
|
"What does this vibration physically feel like?", |
|
|
"Describe the physical sensation produced by this vibration.", |
|
|
"How would you characterize the tactile feeling of this vibration?", |
|
|
"What kind of physical texture or movement does this vibration create?", |
|
|
"In terms of touch, how does this vibration feel on the skin?" |
|
|
], |
|
|
"emotional": [ |
|
|
"What emotion or mood does this vibration convey?", |
|
|
"How does this vibration make you feel emotionally?", |
|
|
"What emotional tone or atmosphere is expressed by this vibration?", |
|
|
"Describe the emotional impression that this vibration gives.", |
|
|
"What kind of mood or feeling is evoked by this vibration?" |
|
|
], |
|
|
"associative": [ |
|
|
"What real-world sensation or object does this vibration resemble?", |
|
|
"What familiar experience or phenomenon does this vibration remind you of?", |
|
|
"Describe what this vibration is similar to in the real world.", |
|
|
"What everyday sound, movement, or event could this vibration represent?", |
|
|
"What real-life action or object feels most like this vibration?" |
|
|
] |
|
|
} |
|
|
|
|
|
|
|
|
with open("data/HapticCap/signal_map_5.1.json", "r", encoding="utf-8") as f: |
|
|
raw_data = json.load(f) |
|
|
|
|
|
llava_data = [] |
|
|
base_dir = "data/HapticCap/aug_signal" |
|
|
|
|
|
for sample_id, sample_content in raw_data.items(): |
|
|
if not isinstance(sample_content, dict): |
|
|
continue |
|
|
|
|
|
|
|
|
pattern = os.path.join(base_dir, f"F{sample_id}_loop*.wav") |
|
|
matched_files = sorted(glob.glob(pattern)) |
|
|
if not matched_files: |
|
|
|
|
|
continue |
|
|
|
|
|
for audio_path in matched_files: |
|
|
|
|
|
for user_id, user_entry in sample_content.items(): |
|
|
if not isinstance(user_entry, dict): |
|
|
continue |
|
|
|
|
|
for modality, key in zip( |
|
|
["sensory", "emotional", "associative"], |
|
|
["free_text_sensory", "free_text_emotional", "free_text_association"] |
|
|
): |
|
|
raw_text = user_entry.get(key, "") |
|
|
if not isinstance(raw_text, str): |
|
|
continue |
|
|
text = raw_text.strip() |
|
|
if not text or text.lower() in ["n.a.", "na", "none"]: |
|
|
continue |
|
|
|
|
|
conv = [ |
|
|
{"from": "human", "value": "<audio>"+random.choice(prompts[modality])}, |
|
|
{"from": "gpt", "value": text} |
|
|
] |
|
|
|
|
|
llava_data.append({ |
|
|
"audios": audio_path.strip('data/'), |
|
|
"conversations": conv |
|
|
}) |
|
|
|
|
|
|
|
|
out_path = "data/HapticCap/haptic_llava.json" |
|
|
with open(out_path, "w", encoding="utf-8") as f: |
|
|
json.dump(llava_data, f, ensure_ascii=False, indent=2) |
|
|
|
|
|
print(f"✅ Saved {len(llava_data)} samples to {out_path}") |
|
|
|