/// <summary>
        /// 語音辨識事件
        /// </summary>
        private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //if (StopDetect != true)
            {
                //Show Sppech Confidence number on screen
                //Show Sppech Confidence number on screen
                Speech_Confidence.Content = "Speaking Accuracy" + "\r\n" + e.Result.Confidence.ToString();

                //設定語音信度門檻值
                if (e.Result.Confidence >= BasicMethod.ConfidenceThreshold)
                {
                    Console.WriteLine(e.Result.Text);

                    //語音辨識跟單字比對
                    if (e.Result.Semantics.Value.ToString().ToLower() == vocabulary.Give_StudentsSentence(posture_number).ToLower())
                    {
                        //Firebase上傳資料
                        FirebaseUpload.Upload(ActivityTitle, "正確", new Speech(txtVocabulary.Text.Trim(), e.Result.Confidence));

                        if (Select_Item.SetPeerSentenceGameMode == true)
                        {
                            //新增語音辨識信心度到List
                            SpeechConfidenceList.Add(BasicMethod.GiveSpeechConfidenceScore(e.Result.Confidence));

                            Console.WriteLine("總分" + TotalTime);

                            Console.WriteLine("語音分數" + BasicMethod.GiveSpeechConfidenceScore(e.Result.Confidence));
                        }

                        //顯示正確圖示
                        Speech_Correct.Visibility = Visibility.Visible;

                        //將語音辨識結果設為True
                        Speech_Result = true;

                        //播放正確音效
                        SoundPlay.PlaySoundCorrect();

                        //通知事件,只是為了再次呼叫 檢查正確與否的方法,所以PostureWords 設為空值
                        if (!Speech_Result == false && !Posture_Result == false)
                        {
                            ReturnPostureWords returnPostureWords = new ReturnPostureWords()
                            {
                                PostureWords = ""
                            };
                            Success_Change_word(this, returnPostureWords);
                        }
                    }
                    else
                    {
                        //如果答錯就記錄到Firebase 但是也要設定門檻才不容易發生誤判
                        if (txtVocabulary.Text != null || e.Result.Confidence >= 0.35)
                        {
                            //Firebase上傳資料
                            FirebaseUpload.Upload(ActivityTitle, "錯誤", new Speech(txtVocabulary.Text.Trim(), e.Result.Semantics.Value.ToString(), e.Result.Confidence));
                        }
                    }
                }
            }
        }
Пример #2
0
 //播放正確音效,//播放音效,用執行序來呼叫
 public void PlayCorrectSound()
 {
     // 播放音效,用執行序來呼叫
     this.Dispatcher.Invoke((Action)(() =>
     {
         SoundPlay.PlaySoundCorrect();
     }));
 }
        /// <summary>
        /// 判斷成功事件,姿勢正確會呼叫此方法
        /// </summary>
        private void Success_Change_word(object sender, EventArgs e)
        {
            //停止時間
            dispatcherGameTimer.Stop();

            //姿勢正確會呼叫Success_Change_word,並把姿勢正確的圖示顯示出來
            Posture_Correct.Visibility = Visibility.Visible;

            Posture_Result = true;

            // 播放音效,用執行序來呼叫
            this.Dispatcher.Invoke((Action)(() =>
            {
                if (PostureSoundStatus != true)
                {
                    SoundPlay.PlaySoundCorrect();
                    PostureSoundStatus = true;

                    if (txtVocabulary.Text != null)
                    {
                        //Firebase上傳姿勢資料
                        FirebaseUpload.Upload(ActivityTitle, new Posture(txtVocabulary.Text.Trim(), 1));
                    }
                }
            }));

            if (!Speech_Result == false && !Posture_Result == false && !Speech_Enable == false)
            {
                //Hide Example Image
                this.exampleImage.Visibility = Visibility.Collapsed;

                Speech_Enable = false;

                //紀錄遊戲時間分數,以時間當作積分,當遊戲模式啟動
                if (Select_Item.SetVocabularyGameMode == true)
                {
                    //把語音辨識信心度當成分數
                    TotalTime += SpeechConfidenceList.Max(x => x);
                    //做出的動作越快分數越高
                    TotalTime += GameTimer;

                    Console.WriteLine("姿勢辨識總時間" + TotalTime + "剩餘時間" + GameTimer);

                    FirebaseUpload.Upload_Rakn_Point(Students.StudentsName, RankData.Rank_Vocabulary, TotalTime);
                }
                //Show Sentence
                this.txtSentence.Visibility = Visibility.Visible;

                //顯示句子
                txtSentence.Text = vocabulary.Give_Sentence(posture_number);

                //需要用微軟的TextToSpeech念出句子,因為Azure Text To Speech 只能調整單一語言
                textToSpeech.MicrosoftTextToSpeech(txtSentence.Text.ToString());
                //textToSpeech.SpeechMethod(txtSentence.Text.ToString());

                txtDetection.Content = "Example Sentence";
            }
        }
        /// <summary>
        /// 判斷成功事件,姿勢正確會呼叫此方法
        /// </summary>
        private void Success_Change_word(object sender, EventArgs e)
        {
            //停止時間
            dispatcherGameTimer.Stop();

            //姿勢正確會呼叫Success_Change_word,並把姿勢正確的圖示顯示出來
            Posture_Correct.Visibility = Visibility.Visible;

            Posture_Result = true;

            // 播放音效,用執行序來呼叫
            this.Dispatcher.Invoke((Action)(() =>
            {
                if (PostureSoundStatus != true)
                {
                    SoundPlay.PlaySoundCorrect();
                    PostureSoundStatus = true;

                    if (txtVocabulary.Text != null)
                    {
                        //Firebase上傳姿勢資料
                        FirebaseUpload.Upload(ActivityTitle, new Posture(txtVocabulary.Text.Trim(), 1));
                    }
                }
            }));

            if (!Speech_Result == false && !Posture_Result == false && !Speech_Enable == false)
            {
                //Hide Example Image
                this.exampleImage.Visibility = Visibility.Collapsed;

                Speech_Enable = false;

                //傳給對方讓它顯示句子
                sokcet_Connect.SendDataToServer((int)BasicMethod.TriggerButtonCode.Successful);

                // 紀錄遊戲時間分數,以時間當作積分,當遊戲模式啟動
                if (Select_Item.SetPeerVocabularyGameMode == true)
                {
                    //把語音辨識信心度當成分數
                    TotalTime += SpeechConfidenceList.Max(x => x);
                    //做出的動作越快分數越高
                    TotalTime += GameTimer;

                    Console.WriteLine("姿勢辨識總時間" + TotalTime + "剩餘時間" + GameTimer);

                    //回存遊戲分數
                    FirebaseUpload.Upload_Rakn_Point(Students.StudentsName, RankData.Rank_PeerVocabulary, TotalTime);
                }

                ShowSentence();
            }
        }
Пример #5
0
        /// <summary>
        /// 判斷成功事件
        /// </summary>
        private void Success_Change_word(object sender, EventArgs e)
        {
            if (e != null)
            {
                //停止時間
                dispatcherGameTimer.Stop();

                //把事件傳過來的值拿下來,(Ps.現在傳過來的是一個繼承 EventArgs 的 Class 且裡面包含 PostureWords 欄位)
                var TargetWords = (e as ReturnPostureWords).PostureWords;

                Console.WriteLine(TargetWords);

                if (TaskWords.Contains(TargetWords))
                {
                    //Firebase上傳姿勢資料
                    FirebaseUpload.Upload(ActivityTitle, txtVocabulary.Text.Trim(), new Posture(txtVocabulary.Text.Trim(), TargetWords, 1));

                    //移除答對單字
                    TaskWords.Remove(TargetWords);

                    //顯示剩下幾個單字
                    txtCountWords.Content = (String.Format("Target : {0}", TaskWords.Count.ToString()));

                    Console.WriteLine(TaskWords.Count);

                    // 播放音效,用執行序來呼叫
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        SoundPlay.PlaySoundCorrect();
                    }));

                    if (TaskWords.Count == 0)
                    {
                        //姿勢正確會呼叫Success_Change_word,並把姿勢正確的圖示顯示出來
                        Posture_Correct.Visibility = Visibility.Visible;
                        Posture_Result             = true;
                        //txtCountWords.Content = ("答對------輪到對方回答");
                    }
                }
                else
                {
                    return;
                }
            }

            if (!Speech_Result == false && !Posture_Result == false && !Speech_Enable == false)
            {
                //Show Sentence
                this.txtSentence.Visibility = Visibility.Visible;

                //Hide Example Image
                this.exampleImage.Visibility = Visibility.Collapsed;

                Speech_Enable = false;

                //把語音辨識信心度當成分數
                TotalTime += SpeechConfidenceList.Max(x => x);

                //做出的動作越快分數越高
                TotalTime += GameTimer;

                Console.WriteLine("姿勢辨識總時間" + TotalTime + "剩餘時間" + GameTimer);

                //回存遊戲分數
                FirebaseUpload.Upload_Rakn_Point(Students.StudentsName, RankData.Rank_PeerInteractive, TotalTime);

                //把姿勢索引傳過去
                sokcet_Connect.SendDataToServer(posture_number + 1);
            }
        }
        /// <summary>
        /// 判斷成功事件,姿勢正確會呼叫此方法
        /// </summary>
        private void Success_Change_word(object sender, EventArgs e)
        {
            //停止時間
            dispatcherGameTimer.Stop();

            //姿勢正確會呼叫Success_Change_word,並把姿勢正確的圖示顯示出來
            Posture_Correct.Visibility = Visibility.Visible;

            Posture_Result = true;

            //把事件傳過來的值拿下來,(Ps.現在傳過來的是一個繼承 EventArgs 的 Class 且裡面包含 PostureWords 欄位)
            var TargetWords = (e as ReturnPostureWords).PostureWords;

            // 播放音效,用執行序來呼叫
            this.Dispatcher.Invoke((Action)(() =>
            {
                if (PostureSoundStatus != true)
                {
                    SoundPlay.PlaySoundCorrect();
                    PostureSoundStatus = true;

                    if (txtVocabulary.Text != null)
                    {
                        //Firebase上傳姿勢資料
                        //FirebaseUpload.Upload(ActivityTitle, new Posture(txtVocabulary.Text.Trim(), 1));
                    }
                }
            }));

            //檢查是否包含單字
            if (TaskWords.Contains(TargetWords))
            {
                TaskWords.Remove(TargetWords);
                txtCountWords.Content = (String.Format("Target : {0}", TaskWords.Count.ToString()));
                Console.WriteLine(TaskWords.Count);

                //Firebase上傳姿勢資料
                FirebaseUpload.Upload(ActivityTitle, txtVocabulary.Text.Trim(), new Posture(txtVocabulary.Text.Trim(), TargetWords, 1));
            }

            //檢查是否都通過
            if (!Speech_Result == false && !Posture_Result == false && !Speech_Enable == false && TaskWords.Count == 0)
            {
                //Hide Example Image
                this.exampleImage.Visibility = Visibility.Collapsed;

                Speech_Enable = false;

                //傳給對方讓它顯示句子
                sokcet_Connect.SendDataToServer((int)BasicMethod.TriggerButtonCode.Successful);

                // 紀錄遊戲時間分數,以時間當作積分,當遊戲模式啟動
                if (Select_Item.SetPeerSentenceGameMode == true)
                {
                    //把語音辨識信心度當成分數
                    TotalTime += SpeechConfidenceList.Max(x => x);
                    //做出的動作越快分數越高
                    TotalTime += GameTimer;

                    Console.WriteLine("姿勢辨識總時間" + TotalTime + "剩餘時間" + GameTimer);

                    //回存遊戲分數
                    FirebaseUpload.Upload_Rakn_Point(Students.StudentsName, RankData.Rank_PeerInteractive, TotalTime);
                }

                ShowSentence();
            }
        }