Пример #1
0
        private void ConfirmButton_Click(object sender, RoutedEventArgs e)
        {
            string _endpoint = "";
            string _key      = "";

            try
            {
                _key = key.Text.Trim();
                string region = ((ComboBoxItem)endpoint.SelectedItem).Content.ToString().Trim();
                _endpoint = EndpointToUriConverter.azureRegionToEndpointMapping[region];
            }
            catch
            {
                MessageBox.Show("Key or Region cannot be empty!", "Invalid Input");
                return;
            }

            if (AzureRuntimeService.IsValidUserAccount(_key, _endpoint))
            {
                // Delete previous user account
                AzureAccount.GetInstance().Clear();
                AzureAccountStorageService.DeleteUserAccount();
                // Create and save new user account
                string _region = ((ComboBoxItem)endpoint.SelectedItem).Content.ToString().Trim();
                AzureAccount.GetInstance().SetUserKeyAndRegion(_key, _region);
                AzureAccountStorageService.SaveUserAccount(AzureAccount.GetInstance());
                AzureRuntimeService.IsAzureAccountPresentAndValid = true;
                SwitchViewToPreviousPage();
            }
            else
            {
                MessageBox.Show("Invalid Azure Account.\nIs your account expired?\nAre you connected to WiFi?");
            }
        }
 private void CancelButton_Click(object sender, RoutedEventArgs e)
 {
     if (audioListView.IsVisible)
     {
         List <IVoice> rankedAudioListCacheCopy = rankedAudioListCache.Select(x => (IVoice)x.Clone()).ToList();
         AudioSettingService.preferredVoices = new ObservableCollection <IVoice>(rankedAudioListCacheCopy);
     }
     if ((AudioSettingService.selectedVoiceType == VoiceType.AzureVoice &&
          !AzureRuntimeService.IsAzureAccountPresent()) ||
         (AudioSettingService.selectedVoiceType == VoiceType.WatsonVoice &&
          !WatsonRuntimeService.IsWatsonAccountPresent()))
     {
         ComputerVoice defaultVoiceSelected = computerVoiceComboBox.SelectedItem as ComputerVoice;
         DialogConfirmedHandler(VoiceType.ComputerVoice, defaultVoiceSelected, previewCheckbox.IsChecked.GetValueOrDefault());
     }
 }
        private void SpeakButton_Click(object sender, RoutedEventArgs e)
        {
            string textToSpeak = spokenText.Text.Trim();

            if (string.IsNullOrEmpty(textToSpeak))
            {
                return;
            }
            IVoice voice = ((Button)sender).CommandParameter as IVoice;

            if (voice == null)
            {
                voice = SelectedVoice;
            }
            if (voice is ComputerVoice)
            {
                ComputerVoiceRuntimeService.SpeakString(textToSpeak, voice as ComputerVoice);
            }
            else if (voice is AzureVoice && !IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName))
            {
                AzureRuntimeService.SpeakString(textToSpeak, voice as AzureVoice);
            }
            else if (voice is AzureVoice && IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName))
            {
                string dirPath  = System.IO.Path.GetTempPath() + AudioService.TempFolderName;
                string filePath = dirPath + "\\" +
                                  string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName);
                AzureRuntimeService.PlaySavedAudioForPreview(filePath);
            }
            else if (voice is WatsonVoice && !IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName))
            {
                WatsonRuntimeService.Speak(textToSpeak, voice as WatsonVoice);
            }
            else if (voice is WatsonVoice && IsSameTextSpokenBySamePerson(textToSpeak, voice.VoiceName))
            {
                string dirPath  = System.IO.Path.GetTempPath() + AudioService.TempFolderName;
                string filePath = dirPath + "\\" +
                                  string.Format(ELearningLabText.AudioPreviewFileNameFormat, voice.VoiceName);
                AzureRuntimeService.PlaySavedAudioForPreview(filePath);
            }
        }
Пример #4
0
        public static void SaveStringToWaveFiles(string notesText, string folderPath, string fileNameFormat)
        {
            TaggedText    taggedNotes   = new TaggedText(notesText);
            List <string> stringsToSave = taggedNotes.SplitByClicks();

            //MD5 md5 = MD5.Create();

            for (int i = 0; i < stringsToSave.Count; i++)
            {
                string textToSave   = stringsToSave[i];
                string baseFileName = string.Format(fileNameFormat, i + 1);

                // The first item will autoplay; everything else is triggered by a click.
                string fileName = i > 0 ? baseFileName + " (OnClick)" : baseFileName;
                string filePath = folderPath + "\\" + fileName + ".wav";

                switch (AudioSettingService.selectedVoiceType)
                {
                case VoiceType.ComputerVoice:
                    ComputerVoiceRuntimeService.SaveStringToWaveFile(textToSave, filePath,
                                                                     AudioSettingService.selectedVoice as ComputerVoice);
                    break;

                case VoiceType.AzureVoice:
                    AzureRuntimeService.SaveStringToWaveFileWithAzureVoice(textToSave, filePath,
                                                                           AudioSettingService.selectedVoice as AzureVoice);
                    break;

                case VoiceType.WatsonVoice:
                    WatsonRuntimeService.SaveStringToWaveFile(textToSave, filePath,
                                                              AudioSettingService.selectedVoice as WatsonVoice);
                    break;

                default:
                    break;
                }
            }
        }
Пример #5
0
 private void CancelButton_Click(object sender, RoutedEventArgs e)
 {
     worker.CancelAsync();
     AzureRuntimeService.Cancel();
     Dispatcher.Invoke(() => { Close(); });
 }