bool CheckSpeakReady(out SpeechSynthesizer speaker, out Settings settings, out WordConvertionItems dic, out string errorMsg) { speaker = new SpeechSynthesizer(); errorMsg = ""; settings = null; dic = null; if (!CheckSettings()) { errorMsg = "读取配置文件错误"; return(false); } if (!LoadSettings(out settings, out dic)) { errorMsg = "读取配置文件错误"; return(false); } if (!CheckVoicer(speaker, settings.voicerName)) { errorMsg = $"未能获取到语音者{settings.voicerName}"; return(false); } return(true); }
// 读取配置文件 bool LoadSettings(out Settings settings, out WordConvertionItems dic) { string settingsStr = File.ReadAllText(settingsPath); string dicStr = File.ReadAllText(dicPath); try { settings = JsonConvert.DeserializeObject <Settings>(settingsStr); dic = JsonConvert.DeserializeObject <WordConvertionItems>(dicStr); return(true); } catch (Exception e) { settings = null; dic = null; return(false); } }
bool InitSpeaker(out SpeechSynthesizer speaker, out Settings settings, out WordConvertionItems dic, out string errorMsg) { if (CheckSpeakReady(out speaker, out settings, out dic, out errorMsg)) { speaker.SelectVoice(settings.voicerName); if (settings.SpeakRate > 10) { settings.SpeakRate = 10; } if (settings.SpeakRate < -10) { settings.SpeakRate = -10; } speaker.Rate = settings.SpeakRate; speaker.Volume = settings.speakVolume; return(true); } return(false); }