Ejemplo n.º 1
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            BingSpeechLanguageResult speechLanguage = value as BingSpeechLanguageResult;

            var parts = speechLanguage.VoiceLabel.Split(',').Last();

            return($"{parts.Split(')').First().Replace("RUS", "")} ({speechLanguage.Gender}, {new System.Globalization.CultureInfo(speechLanguage.Locale).DisplayName})");
        }
Ejemplo n.º 2
0
        //calls the Bing Speech API Synthesize method to perform speech synthesize
        public async static Task <IInputStream> SynthesizeTextToSpeechAsync(string textContent, BingSpeechLanguageResult language)
        {
            IInputStream fileResult = null;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization = new HttpCredentialsHeaderValue("Bearer", await GetAccessTokenAsync());
                client.DefaultRequestHeaders.Add("X-Microsoft-OutputFormat", Common.AppConstants.SynthesisOutputType);
                client.DefaultRequestHeaders.Add("X-Search-AppId", Common.AppConstants.AppId);
                client.DefaultRequestHeaders.Add("X-Search-ClientID", Common.AppConstants.ClientId);
                client.DefaultRequestHeaders.Add("User-Agent", Common.AppConstants.AppDisplayName);

                try
                {
                    var response = await client.PostAsync(new Uri(Common.BingSpeechConstants.SynthesisBaseUrl), new HttpStringContent(GenerateSsml(language.Locale, language.Gender, language.VoiceLabel, $"{textContent}")));

                    fileResult = await response.Content.ReadAsInputStreamAsync();
                }
                catch (Exception ex)
                {
                }
            }

            return(fileResult);
        }