Beispiel #1
0
 private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         SetWebBrowserFeatures(10);
         PronScoreWebBrowser.Navigate(new Uri(System.IO.Path.Combine(System.Windows.Forms.Application.StartupPath, @"pronscore.html")));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #2
0
        private void Button_Stop_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                waveSource.StopRecording();
                // Close Wave (not needed under synchronous situation)
                if (waveSource != null)
                {
                    waveSource.Dispose();
                    waveSource = null;
                }

                var response = request.GetResponse();
                using (var responseStream = response.GetResponseStream())
                    using (var streamReader = new StreamReader(responseStream))
                    {
                        var         responseJsonText = streamReader.ReadToEnd(); // The result in JSON format, with pronunciation score
                        ScoreResult result           = JsonConvert.DeserializeObject <ScoreResult>(responseJsonText);

                        if (null != result && "Success" == result.RecognitionStatus)
                        {
                            NBestItem nBestItem = result.NBest[0];
                            var       pronScore = JsonConvert.SerializeObject(nBestItem);

                            PronScoreWebBrowser.InvokeScript("generatePronScoreTable", pronScore);
                            PronScoreWebBrowser.InvokeScript("generatePhoneScoreTable", pronScore);
                            PronScoreWebBrowser.Visibility = Visibility.Visible;
                            List <WordsItem> witems = result.NBest[0].Words;
                            for (int i = 0; i < witems.Count; i++)
                            {
                                WordsItem w = witems[i];
                                if (w.AccuracyScore <= 60.0)
                                {
                                    ChangeColor(Colors.Red, ReferenceText, w.Word.ToLower(), w.AccuracyScore);
                                }
                                else if (w.AccuracyScore <= 70.0)
                                {
                                    ChangeColor(Colors.Orange, ReferenceText, w.Word.ToLower(), w.AccuracyScore);
                                }
                                else
                                {
                                    ChangeColor(Colors.Green, ReferenceText, w.Word.ToLower(), w.AccuracyScore);
                                }
                            }
                        }
                        else
                        {
                            if (null != result)
                            {
                                MessageBox.Show($"Recognition status: {result.RecognitionStatus}");
                            }
                        }
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                progressRing.IsActive = false;
                StartBut.Visibility   = Visibility.Visible;
                StopBut.Visibility    = Visibility.Collapsed;
            }
        }