This commit is contained in:
owenchen committed 2026-06-02 11:00:43 +08:00
1 parent 330515ff2c
commit cfe55502cf
2 files changed
+113 -27

No files matched your search

@@ -128,4 +128,85 @@ namespace CloudBuilder.AI.Policy
[System.ComponentModel.Description("普通话(中国大陆) 小神精女(女性)-27")]
Theresa,
}
public static class ChineseTtsVoiceRandom
{
private static readonly Random _random = new Random();
private static ChineseTtsVoice Default = ChineseTtsVoice.Sherpa2;
private static ChineseTtsVoice DefaultFemale = ChineseTtsVoice.Sherpa0;
private static ChineseTtsVoice DefaultMale = ChineseTtsVoice.Sherpa4;
// 所有男性列表(只定义一次)
private static readonly List<ChineseTtsVoice> _allMales = new()
{
ChineseTtsVoice.Sherpa4,
ChineseTtsVoice.Sherpa3,
ChineseTtsVoice.Sherpa1,
ChineseTtsVoice.Aaishe10,
ChineseTtsVoice.Aaishe15,
ChineseTtsVoice.Fanchen10,
ChineseTtsVoice.Fanchen110,
ChineseTtsVoice.Fanchen15
};
// 所有女性列表
private static readonly List<ChineseTtsVoice> _allFemales = new()
{
ChineseTtsVoice.Sherpa0,
ChineseTtsVoice.Sherpa2,
ChineseTtsVoice.Aaishe6,
ChineseTtsVoice.Aaishe14,
ChineseTtsVoice.Aaishe18,
ChineseTtsVoice.Aaishe1,
ChineseTtsVoice.Fanchen6,
ChineseTtsVoice.Fanchen2,
ChineseTtsVoice.Fanchen14,
ChineseTtsVoice.Fanchen20,
ChineseTtsVoice.Fanchen36,
ChineseTtsVoice.Melo,
ChineseTtsVoice.Eula,
ChineseTtsVoice.Theresa
};
// 1. 随机取任意一个
public static ChineseTtsVoice GetRandom()
{
var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast<ChineseTtsVoice>().ToList();
return all[_random.Next(all.Count)];
}
// 2. 随机女性
public static ChineseTtsVoice GetRandomFemale()
{
return _allFemales[_random.Next(_allFemales.Count)];
}
// 3. 随机男性
public static ChineseTtsVoice GetRandomMale()
{
return _allMales[_random.Next(_allMales.Count)];
}
// 4. 随机男性(传入要排除的声音,通用版 ✅)
public static ChineseTtsVoice GetRandomMaleExclude(ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa4)
{
var filtered = _allMales.Where(m => m != excludeVoice).ToList();
return filtered[_random.Next(filtered.Count)];
}
// 5. 随机女性(传入要排除的声音,通用版 ✅)
public static ChineseTtsVoice GetRandomFemaleExclude(ChineseTtsVoice excludeVoice = ChineseTtsVoice.Sherpa0)
{
var filtered = _allFemales.Where(f => f != excludeVoice).ToList();
return filtered[_random.Next(filtered.Count)];
}
// 1. 随机取任意一个
public static ChineseTtsVoice GetRandomExclude()
{
var all = Enum.GetValues(typeof(ChineseTtsVoice)).Cast<ChineseTtsVoice>().ToList();
all = all.Where(f => f != DefaultFemale && f != DefaultMale).ToList();
return all[_random.Next(all.Count)];
}
}
}