package com.xly.tts.bean; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.List; /** * 语音分组数据传输对象 */ @Data @Builder @NoArgsConstructor @AllArgsConstructor public class VoiceGroupDTO implements Serializable { private static final long serialVersionUID = 1L; /** * 分组键(如:languageCode, locale, gender) */ private String groupKey; /** * 分组值(如:zh, en-US, Female) */ private String groupValue; /** * 分组显示名称 */ private String groupDisplayName; /** * 语音数量 */ private Integer voiceCount; /** * 分组内的语音列表 */ private List voices; /** * 是否为默认分组 */ private Boolean isDefaultGroup; /** * 排序权重 */ private Integer sortWeight; // 静态工厂方法 public static VoiceGroupDTO byLanguage(String languageCode, String displayName, List voices) { return VoiceGroupDTO.builder() .groupKey("language") .groupValue(languageCode) .groupDisplayName(displayName) .voiceCount(voices != null ? voices.size() : 0) .voices(voices) .sortWeight(getLanguageSortWeight(languageCode)) .build(); } public static VoiceGroupDTO byLocale(String locale, List voices) { return VoiceGroupDTO.builder() .groupKey("locale") .groupValue(locale) .groupDisplayName(locale) .voiceCount(voices != null ? voices.size() : 0) .voices(voices) .sortWeight(getLocaleSortWeight(locale)) .build(); } public static VoiceGroupDTO byGender(String gender, List voices) { String displayName = "Female".equalsIgnoreCase(gender) ? "女声" : "男声"; return VoiceGroupDTO.builder() .groupKey("gender") .groupValue(gender) .groupDisplayName(displayName) .voiceCount(voices != null ? voices.size() : 0) .voices(voices) .sortWeight("Female".equalsIgnoreCase(gender) ? 1 : 2) .build(); } private static Integer getLanguageSortWeight(String languageCode) { switch (languageCode.toLowerCase()) { case "zh": return 1; // 中文优先 case "en": return 2; // 英文其次 case "ja": return 3; // 日语 case "ko": return 4; // 韩语 case "fr": return 5; // 法语 case "de": return 6; // 德语 case "es": return 7; // 西班牙语 default: return 100; // 其他语言 } } private static Integer getLocaleSortWeight(String locale) { if (locale == null) return 1000; if (locale.startsWith("zh-CN")) return 1; // 简体中文 if (locale.startsWith("zh-TW")) return 2; // 繁体中文 if (locale.startsWith("zh-HK")) return 3; // 香港中文 if (locale.startsWith("en-US")) return 4; // 美式英语 if (locale.startsWith("en-GB")) return 5; // 英式英语 if (locale.startsWith("ja-JP")) return 6; // 日语 if (locale.startsWith("ko-KR")) return 7; // 韩语 return 100; // 其他 } }