import com.alibaba.fastjson2.*; import com.cmvr.tts.service.impl.VoxCpmTtsClient; import io.minio.*; import java.io.*; import java.nio.file.*; import java.sql.Connection; import java.time.Instant; import java.util.*; import java.util.concurrent.*; /** Final verification of self-model dataset, actual request metadata and both audio copies. */ public class EmotionStorageAudit { public static void main(String[] args)throws Exception{ var root=EmotionProduction.ROOT;JSONObject progress=JSON.parseObject(Files.readString(root.resolve("progress.json"))); if(!"COMPLETE".equals(progress.getString("state"))||progress.getIntValue("completed")!=3000)throw new IOException("Emotion production has not completed"); Map jobs=new HashMap<>();for(String line:Files.readAllLines(root.resolve("plan.jsonl"))){JSONObject j=JSON.parseObject(line);jobs.put(j.getString("id"),j);} CorpusDatabase.init();JSONArray rows;try(Connection c=CorpusDatabase.connect()){ EmotionProduction.audit(c); rows=CorpusDatabase.query(c,"SELECT c.id,c.text,c.voice,c.language,c.emotion,c.model,c.audio_file_path,c.file_size,t.model AS task_model,t.emotion AS task_emotion,t.sample_rate,t.status,t.audio_file_path AS task_audio FROM tts_corpus_info c JOIN tts_synthesize_task t ON t.id=c.id AND t.remark=c.remark WHERE c.remark=?",EmotionProduction.BATCH); } if(rows.size()!=3000||jobs.size()!=3000)throw new IOException("Final dataset join mismatch"); MinioClient minio=CorpusDatabase.minio();String bucket=CorpusDatabase.property("minio.bucketName");ExecutorService pool=Executors.newFixedThreadPool(6);CompletionService finished=new ExecutorCompletionService<>(pool); try{ for(Object value:rows){JSONObject row=(JSONObject)value;finished.submit(()->{ String id=row.getString("id");JSONObject job=jobs.get(id);if(job==null)throw new IOException("Unexpected dataset record"); for(String k:List.of("text","model","voice","language","emotion"))if(!job.getString(k).equals(row.getString(k)))throw new IOException("Plan/database mismatch "+id); String object="tts/"+EmotionProduction.BATCH+"/"+job.getString("emotion")+"/"+id+".wav"; if(!"voxcpm2".equals(row.getString("task_model"))||!job.getString("emotion").equals(row.getString("task_emotion"))||!"48000".equals(row.getString("sample_rate"))||!"2".equals(row.getString("status"))||!object.equals(row.getString("audio_file_path"))||!object.equals(row.getString("task_audio")))throw new IOException("Task model/audio metadata mismatch "+id); JSONObject receipt=JSON.parseObject(Files.readString(root.resolve("receipts").resolve(id+".json"))); if(!"IMPORTED".equals(receipt.getString("state"))||!receipt.getJSONObject("request").equals(VoxCpmTtsClient.request(EmotionProduction.task(job))))throw new IOException("Request/receipt mismatch "+id); Path backup=Path.of(receipt.getString("backup_file")).toAbsolutePath().normalize();if(!backup.startsWith(EmotionProduction.AUDIO.toAbsolutePath().normalize()))throw new IOException("Unexpected backup path"); byte[] bytes=Files.readAllBytes(backup);String hash=CorpusDatabase.sha(bytes);if(!hash.equals(receipt.getString("sha256"))||bytes.length!=row.getLongValue("file_size"))throw new IOException("E backup mismatch "+id);EmotionProduction.quality(bytes); try(InputStream in=minio.getObject(GetObjectArgs.builder().bucket(bucket).object(object).build())){if(!hash.equals(CorpusDatabase.sha(in.readAllBytes())))throw new IOException("MinIO mismatch");}catch(Exception error){throw new IOException("MinIO verification failed for "+id);} JSONObject verified=new JSONObject();verified.put("id",id);verified.put("model","voxcpm2");verified.put("emotion",job.getString("emotion"));verified.put("object_path",object);verified.put("backup_file",backup.toString());verified.put("sha256",hash);return verified; });} List verified=new ArrayList<>();for(int n=1;n<=3000;n++){verified.add(finished.take().get());if(n%500==0)System.out.println("EMOTION_STORAGE_VERIFIED "+n+"/3000");} Path manifest=root.resolve("minio-backup-verified.jsonl");try(BufferedWriter w=Files.newBufferedWriter(manifest)){for(JSONObject v:verified){w.write(v.toJSONString());w.newLine();}} JSONObject audit=new JSONObject();audit.put("checked_at",Instant.now().toString());audit.put("count",3000);audit.put("model","voxcpm2");audit.put("database_model_emotion_paths_verified",true);audit.put("actual_request_matches_plan",true);audit.put("minio_sha256_verified",true);audit.put("e_backup_sha256_verified",true);audit.put("manifest_sha256",CorpusDatabase.sha(Files.readAllBytes(manifest)));audit.put("emotion_validation_scope","Requested emotion metadata verified; sample audition accepted by user; no per-clip human emotion annotation");EmotionProduction.save(root.resolve("storage-audit.json"),audit); Path metadata=EmotionProduction.AUDIO.getParent().resolve("metadata");Files.createDirectories(metadata);for(String name:List.of("plan.jsonl","source-review.json","text-quality-summary.json","database-audit.json","progress.json","storage-audit.json","minio-backup-verified.jsonl")){Files.copy(root.resolve(name),metadata.resolve(name),StandardCopyOption.REPLACE_EXISTING);if(!CorpusDatabase.sha(Files.readAllBytes(root.resolve(name))).equals(CorpusDatabase.sha(Files.readAllBytes(metadata.resolve(name)))))throw new IOException("Metadata backup mismatch");} System.out.println("EMOTION_AUDIT_OK "+audit); }finally{pool.shutdownNow();}System.exit(0); } }