private void LoadGameVoices() { string voicesPath = Path.Combine(xVaSynthPath, "xVASynthVoices.json"); if (!File.Exists(voicesPath)) { SMonitor.Log($"Voices file not found at {voicesPath}"); return; } using (StreamReader reader = File.OpenText(voicesPath)) { JsonSerializer serializer = new JsonSerializer(); gameVoices = (GameVoices)serializer.Deserialize(reader, typeof(GameVoices)); int count = 0; foreach (var kvp in gameVoices.games) { count += kvp.Value.Count; Monitor.Log($"Loaded {kvp.Value.Count} voices for {kvp.Key}"); } Monitor.Log($"Loaded {count} voices for {gameVoices.games.Count} games", LogLevel.Debug); } foreach (var ss in Config.NPCGameVoices.Split(',')) { var ngv = ss.Split(':'); if (ngv.Length != 3) { continue; } voiceDict[ngv[0]] = new GameVoice(ngv[1], ngv[2]); } }
public static void PlayDialogue(string name, string dialogue) { if (!voiceDict.ContainsKey(name)) { SMonitor.Log($"No game voice set for {name}"); return; } GameVoice voice = voiceDict[name]; if (!gameVoices.games.ContainsKey(voice.game)) { SMonitor.Log($"Game {voice.game} not found for {name}", LogLevel.Warn); } if (!gameVoices.games[voice.game].Exists(v => v.id == voice.id)) { SMonitor.Log($"Voice {voice.id} for game {voice.game} not found for {name}", LogLevel.Warn); } SendToXVASynth(voice, dialogue); }
private static async void SendToXVASynth(GameVoice voice, string dialogue) { currentDialogue = dialogue; SMonitor.Log($"Sending speech {dialogue} for voice {voice.id}, game {voice.game} to xVASynth"); GameVoiceText text = new GameVoiceText() { gameId = voice.game, voiceId = voice.id, vol = 1f, text = "" }; if (File.Exists(Path.Combine(xVaSynthPath, "output.wav"))) { File.Delete(Path.Combine(xVaSynthPath, "output.wav")); } string speechPath = Path.Combine(xVaSynthPath, "xVASynthText.json"); using (StreamWriter file = File.CreateText(speechPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, text); } if (dialogue == null || dialogue.Length == 0) { return; } if (dialogue.Length <= Config.MaxLettersToPrepare && Config.MillisecondsPrepare > 0) { await Task.Delay(Config.MillisecondsPrepare); } text.text = dialogue; using (StreamWriter file = File.CreateText(speechPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, text); } ticks = 0; CheckForWav(); }