Skip to content

Commit

Permalink
Allow config values to be unspecified and use system defaults.
Browse files Browse the repository at this point in the history
There's a crash on first time you click "Listen" if the 'default' voice isn't available on your PC.
It's more robust to not assume anything about locale or available voices.
  • Loading branch information
kmcnaught committed Apr 9, 2019
1 parent 22ac054 commit f93b43e
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions GAVPI/GAVPI/Core/Engine/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,33 +73,37 @@ public void load_settings()
{
if (element.Name == "Settings")
{
// Warning : can be null

string xml_default_profile_name = element.Attributes.GetNamedItem("default_profile_name").Value;
// Warning : can be null
string xml_default_profile_filepath = element.Attributes.GetNamedItem("default_profile_filepath").Value;

string xml_voice_info = element.Attributes.GetNamedItem("voice_info").Value;
string xml_pushtotalk_mode = element.Attributes.GetNamedItem("pushtotalk_mode").Value;
string xml_pushtotalk_key = element.Attributes.GetNamedItem("pushtotalk_key").Value;
string xml_recognizer_info = element.Attributes.GetNamedItem("recognizer_info").Value;

// If any of these are not specified in settings, we can leave with defaults loaded in Settings constructor.
// This lets us default to an individual's local system locale / available voices.
if (!String.IsNullOrEmpty(xml_voice_info))
voice_info = xml_voice_info;

if (String.IsNullOrEmpty(xml_voice_info) &&
String.IsNullOrEmpty(xml_pushtotalk_mode) &&
String.IsNullOrEmpty(xml_pushtotalk_key) &&
String.IsNullOrEmpty(xml_recognizer_info))
{
throw new Exception("Malformed settings file, some values are null.");
}
else
{
if (!String.IsNullOrEmpty(xml_default_profile_name))
default_profile_name = xml_default_profile_name;

if (!String.IsNullOrEmpty(xml_default_profile_filepath))
default_profile_filepath = xml_default_profile_filepath;
voice_info = xml_voice_info;

if (!String.IsNullOrEmpty(xml_pushtotalk_mode))
pushtotalk_mode = xml_pushtotalk_mode;

if (!String.IsNullOrEmpty(xml_pushtotalk_key))
pushtotalk_key = xml_pushtotalk_key;

if (!String.IsNullOrEmpty(xml_voice_info))
voice_info = xml_voice_info;

if (!String.IsNullOrEmpty(xml_recognizer_info))
recognizer_info = new System.Globalization.CultureInfo(xml_recognizer_info);
}

}
else
{
Expand Down

0 comments on commit f93b43e

Please sign in to comment.