示例#1
0
        /// <summary>
        /// Translates a text string from one language to another.
        /// </summary>
        /// <param name="text">Text to translate</param>
        /// <param name="fromLanguage">Language to translate from.</param>
        /// <param name="toLanguage">Language to translate to.</param>
        /// <returns>The translated text.</returns>
        public static async Task <string> TranslateAsync(string text, TtsLanguageType fromLanguage, TtsLanguageType toLanguage)
        {
            var query    = $"{BaseEndpoint}/Translate?text={text}&from={languages[(int)fromLanguage]}&to={languages[(int)toLanguage]}";
            var response = await Rest.GetAsync(query, ApiKeyHeader);

            if (response.Successful)
            {
                return(response.ResponseBody.StripXml());
            }

            return(string.Empty);
        }
示例#2
0
        /// <summary>
        /// Gets the AudioClip of the passed-in text being spoken in the desired language.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="language"></param>
        /// <returns>Audio Clip of the text to be spoken.</returns>
        public static async Task <AudioClip> SpeakAsync(string text, TtsLanguageType language)
        {
            var query = $"{BaseEndpoint}/Speak?text={text}&language={languages[(int)language]}";

            return(await Rest.GetAudioClipAsync(query, AudioType.WAV, ApiKeyHeader));
        }