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; /// Culture of the voice. [Tooltip("Culture of the voice voice."), SerializeField] private string culture; /// Description of the voice. [Tooltip("Description of the voice.")] public string Description; /// Gender of the voice. [Tooltip("Gender of the voice.")] public Crosstales.RTVoice.Model.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; /// Sample rate in Hz of the voice. [Tooltip("Sample rate in Hz of the voice.")] public int SampleRate; /// Is the voice neural? [Tooltip("Is the voice neural?.")] public bool isNeural; #endregion #region Properties /// Culture of the voice (ISO 639-1). public string Culture { get => culture; set { if (value != null) culture = value.Trim().Replace('_', '-'); } } /// Language of the voice. public SystemLanguage Language => Crosstales.RTVoice.Util.Helper.ISO639ToLanguage(Culture); /// Simplified culture of the voice. [System.Xml.Serialization.XmlIgnoreAttribute] public string SimplifiedCulture => culture.Replace("-", string.Empty); #endregion #region Constructors /// Default. public Voice() { //empty } /// 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). /// Sample rate in Hz of the voice (optional). /// Is the voice neural (optional). public Voice(string name, string description, Crosstales.RTVoice.Model.Enum.Gender gender, string age, string culture, string id = "", string vendor = "unknown", int sampleRate = 0, bool neural = false) { Name = name; Description = description; Gender = gender; Age = age; Culture = culture; Identifier = id; Vendor = vendor; SampleRate = sampleRate; isNeural = neural; } #endregion #region Overridden methods public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) return false; Voice o = (Voice)obj; return Name == o.Name && Culture == o.Culture && Description == o.Description && Gender == o.Gender && Age == o.Age && Identifier == o.Identifier && Vendor == o.Vendor && SampleRate == o.SampleRate && isNeural == o.isNeural; } public override int GetHashCode() { int hash = 0; if (Name != null) hash += Name.GetHashCode(); if (Culture != null) hash += Culture.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(); hash += SampleRate * 17; return hash; } public override string ToString() { return $"{Name} ({Culture}, {Gender})"; } /* 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-2024 crosstales LLC (https://www.crosstales.com)