using UnityEngine;
namespace Crosstales.RTVoice.Model
{
/// Model for a voice.
[System.Serializable]
public class Voice
{
#region Variables
/// Name of the voice.
[Tooltip("Name of the voice.")] public string Name;
/// Description of the voice.
[Tooltip("Description of the voice.")] public string Description;
/// Gender of the voice.
[Tooltip("Gender of the voice.")] public Enum.Gender Gender;
/// Age of the voice.
[Tooltip("Age of the voice.")] public string Age;
/// Identifier of the voice.
[Tooltip("Identifier of the voice.")] public string Identifier = string.Empty;
/// Vendor of the voice.
[Tooltip("Vendor of the voice.")] public string Vendor = string.Empty;
/// Version of the voice.
[Tooltip("Version of the voice.")] public string Version = string.Empty;
/// Sample rate in Hz of the voice.
[Tooltip("Sample rate in Hz of the voice.")] public int SampleRate;
private string culture;
private string simplifiedCulture;
#endregion
#region Properties
/// Culture of the voice (ISO 639-1).
public string Culture
{
get => culture;
set
{
if (value != null)
{
culture = value.Trim().Replace('_', '-');
SimplifiedCulture = culture;
}
}
}
/// Simpified culture of the voice.
public string SimplifiedCulture
{
get => simplifiedCulture;
private set
{
if (value != null)
simplifiedCulture = value.Replace("-", string.Empty);
}
}
#endregion
#region Constructors
/// Instantiate the class.
/// Name of the voice.
/// Description of the voice.
/// Gender of the voice.
/// Age of the voice.
/// Culture of the voice.
/// Identifier of the voice (optional).
/// Vendor of the voice (optional).
/// Version of the voice (optional).
/// Sample rate in Hz of the voice (optional).
public Voice(string name, string description, Enum.Gender gender, string age, string culture, string id = "", string vendor = "unknown", string version = "unknown", int sampleRate = 0)
{
Name = name;
Description = description;
Gender = gender;
Age = age;
Culture = culture;
Identifier = id;
Vendor = vendor;
Version = version;
SampleRate = sampleRate;
}
#endregion
#region Overridden methods
public override string ToString()
{
return Name + " (" + Culture + ", " + Gender + ")";
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
Voice o = (Voice)obj;
return Name == o.Name &&
Description == o.Description &&
Gender == o.Gender &&
Age == o.Age &&
Identifier == o.Identifier &&
Vendor == o.Vendor &&
Version == o.Version &&
SampleRate == o.SampleRate;
}
public override int GetHashCode()
{
int hash = 0;
if (Name != null)
hash += Name.GetHashCode();
if (Description != null)
hash += Description.GetHashCode();
hash += (int)Gender * 17;
if (Age != null)
hash += Age.GetHashCode();
if (Identifier != null)
hash += Identifier.GetHashCode();
if (Vendor != null)
hash += Vendor.GetHashCode();
if (Version != null)
hash += Version.GetHashCode();
hash += SampleRate * 17;
return hash;
}
/*
public override string ToString()
{
System.Text.StringBuilder result = new System.Text.StringBuilder();
result.Append(GetType().Name);
result.Append(Util.Constants.TEXT_TOSTRING_START);
result.Append("Name='");
result.Append(Name);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Description='");
result.Append(Description);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Gender='");
result.Append(Gender);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Age='");
result.Append(Age);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Culture='");
result.Append(Culture);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Identifier='");
result.Append(Identifier);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Vendor='");
result.Append(Vendor);
//result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append("Version='");
result.Append(Version);
//result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER);
result.Append(Util.Constants.TEXT_TOSTRING_DELIMITER_END);
result.Append(Util.Constants.TEXT_TOSTRING_END);
return result.ToString();
}
*/
#endregion
}
}
// © 2015-2020 crosstales LLC (https://www.crosstales.com)