public static bool IsValidUserAccount(string key, string endpoint)
 {
     try
     {
         AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance(endpoint, key);
         string accessToken = auth.GetAccessToken();
         Console.WriteLine("Token: {0}\n", accessToken);
     }
     catch
     {
         Console.WriteLine("Failed authentication.");
         return(false);
     }
     return(true);
 }
        public static void SpeakStringAsync(string textToSpeak, AzureVoice voice)
        {
            RenewCancellationToken();
            string accessToken;
            string dirPath  = Path.GetTempPath() + AudioService.TempFolderName;
            string filePath = dirPath + "\\" +
                              string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName);

            try
            {
                AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance();
                accessToken = auth.GetAccessToken();
                Logger.Log("Token: " + accessToken);
            }
            catch
            {
                Logger.Log("Failed authentication.");
                return;
            }
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            string requestUri = AzureAccount.GetInstance().GetUri();

            if (requestUri == null)
            {
                return;
            }
            var azureVoiceSynthesizer = new SynthesizeAzureVoice();

            azureVoiceSynthesizer.OnAudioAvailable += PlayAudio;
            azureVoiceSynthesizer.OnError          += OnAzureVoiceErrorHandler;
            // Reuse Synthesize object to minimize latency
            azureVoiceSynthesizer.Speak(token, new InputOptions()
            {
                RequestUri = new Uri(requestUri),
                Text       = textToSpeak,
                VoiceType  = voice.voiceType,
                Locale     = voice.Locale,
                VoiceName  = voice.voiceName,
                // Service can return audio in different output format.
                OutputFormat       = AudioOutputFormat.Riff24Khz16BitMonoPcm,
                AuthorizationToken = "Bearer " + accessToken,
            }, filePath).Wait();
        }
        public static bool SaveStringToWaveFileWithAzureVoice(string textToSave, string filePath, AzureVoice voice)
        {
            RenewCancellationToken();
            string accessToken;
            string textToSpeak = GetHumanSpeakNotesForText(textToSave);

            try
            {
                AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance();
                accessToken = auth.GetAccessToken();
                Logger.Log("Token: " + accessToken);
            }
            catch
            {
                Logger.Log("Failed authentication.");
                return(false);
            }
            string requestUri = AzureAccount.GetInstance().GetUri();

            if (requestUri == null)
            {
                return(false);
            }
            var azureVoiceSynthesizer = new SynthesizeAzureVoice();

            azureVoiceSynthesizer.OnAudioAvailable += SaveAudioToWaveFile;
            azureVoiceSynthesizer.OnError          += OnAzureVoiceErrorHandler;

            // Reuse Synthesize object to minimize latency
            azureVoiceSynthesizer.Speak(token, new InputOptions()
            {
                RequestUri = new Uri(requestUri),
                Text       = textToSpeak,
                VoiceType  = voice.voiceType,
                Locale     = voice.Locale,
                VoiceName  = voice.voiceName,
                // Service can return audio in different output format.
                OutputFormat       = AudioOutputFormat.Riff24Khz16BitMonoPcm,
                AuthorizationToken = "Bearer " + accessToken,
            }, filePath).Wait();
            return(true);
        }
 public static bool IsValidUserAccount(bool showErrorMessage = true, string errorMessage = "Failed Azure authentication.")
 {
     try
     {
         string _key      = AzureAccount.GetInstance().GetKey();
         string _endpoint = EndpointToUriConverter.azureRegionToEndpointMapping[AzureAccount.GetInstance().GetRegion()];
         AzureAccountAuthentication auth = AzureAccountAuthentication.GetInstance(_endpoint, _key);
         string accessToken = auth.GetAccessToken();
         Console.WriteLine("Token: {0}\n", accessToken);
     }
     catch
     {
         Console.WriteLine(errorMessage);
         if (showErrorMessage)
         {
             MessageBox.Show(errorMessage);
         }
         return(false);
     }
     return(true);
 }