示例#1
0
        private void QRCodeTimer_Tick(object sender, EventArgs e)
        {
            if (QRCodeBitmap == null)
            {
                return;
            }
            //把ColorFrame的wbData的資料從WriteableBitmap格式,轉成Bitmap格式,才能符合QRcode格式
            ZXing.Result result = reader.Decode(BitmapToWriteableBitmap.BitmapFromWriteableBitmap(QRCodeBitmap));

            if (result != null)
            {
                Console.WriteLine(result.Text);

                //這邊要檢查 List裡有包含單字的陣列
                if (TaskWords.Contains(result.Text))
                {
                    ReturnPostureWords returnPostureWords = new ReturnPostureWords()
                    {
                        PostureWords = result.Text
                    };
                    Success_Change_word(this, returnPostureWords);
                    Console.WriteLine("成功" + result.Text);
                    FirebaseUpload.Upload(ActivityTitle, "正確", new ORcodeObject(result.Text, txtVocabulary.Text, 1));
                }
                else
                {
                    SoundPlay.PlaySoundFailed();
                    //System.Windows.Forms.MessageBox.Show(result.Text);
                    Console.WriteLine("失敗" + result.Text);
                    FirebaseUpload.Upload(ActivityTitle, "錯誤", new ORcodeObject(result.Text, txtVocabulary.Text, 1));
                }
            }
        }
        /// <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));
                        }
                    }
                }
            }
        }
示例#3
0
 //播放正確音效,//播放音效,用執行序來呼叫
 public void PlayWrongSound()
 {
     // 播放音效,用執行序來呼叫
     this.Dispatcher.Invoke((Action)(() =>
     {
         SoundPlay.PlaySoundFailed();
     }));
 }
示例#4
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";
            }
        }
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //註銷掉事件
            bodyFrameReader.FrameArrived    -= BodyFrameReader_FrameArrived;
            _reader.MultiSourceFrameArrived -= _reader_MultiSourceFrameArrived;
            poseture.Poseture_List          -= Success_Change_word;
            dispatcherTimer.Tick            -= DispatcherTimer_Tick;
            dispatcherGameTimer.Tick        -= GameTimer_Tick;
            QRcodeTimer.Tick -= QRCodeTimer_Tick;

            //關閉Socket.io連線
            sokcet_Connect.SocketClose();

            //Stop Text To Speech
            textToSpeech.SpeechPause();

            //Stop SoundPlay
            SoundPlay.PlayStop();

            //停止偵測QRCode
            QRcodeTimer.Stop();

            //暫停拍照倒數時間
            dispatcherTimer.Stop();

            //將音效的狀態設定為初始值
            PostureSoundStatus = false;

            if (_reader != null)
            {
                _reader.Dispose();
                _reader = null;
            }

            if (bodyFrameReader != null)
            {
                bodyFrameReader.Dispose();
                bodyFrameReader = null;
            }

            if (null != this.convertStream)
            {
                this.convertStream.SpeechActive = false;
            }

            if (null != this.speechEngine)
            {
                this.speechEngine.SpeechRecognized          -= this.SpeechRecognized;
                this.speechEngine.SpeechRecognitionRejected -= this.SpeechRejected;
                this.speechEngine.RecognizeAsyncStop();
            }

            PeerMainWidnow peerMainWidnow = new PeerMainWidnow();

            peerMainWidnow.Show();
        }
        /// <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();
            }
        }
示例#8
0
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //Close socket
            sokcet_Connect.SocketClose();

            //註銷掉事件
            bodyFrameReader.FrameArrived    -= BodyFrameReader_FrameArrived;
            _reader.MultiSourceFrameArrived -= _reader_MultiSourceFrameArrived;
            poseture.Poseture_List          -= Success_Change_word;
            dispatcherTimer.Tick            -= DispatcherTimer_Tick;
            QRcodeTimer.Tick -= QRCodeTimer_Tick;

            //Stop Text To Speech
            textToSpeech.SpeechPause();

            //Stop SoundPlay
            SoundPlay.PlayStop();

            //停止偵測QRCode
            QRcodeTimer.Stop();

            //停止拍照倒數時間
            dispatcherTimer.Stop();

            if (_reader != null)
            {
                _reader.Dispose();
                _reader = null;
            }

            if (bodyFrameReader != null)
            {
                bodyFrameReader.Dispose();
                bodyFrameReader = null;
            }

            if (null != this.convertStream)
            {
                this.convertStream.SpeechActive = false;
            }

            if (null != this.speechEngine)
            {
                this.speechEngine.SpeechRecognized          -= this.SpeechRecognized;
                this.speechEngine.SpeechRecognitionRejected -= this.SpeechRejected;
                this.speechEngine.RecognizeAsyncStop();
            }

            //用來判斷該呼叫哪個主頁面
            BasicMethod.CallMainWindow();
        }
示例#9
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();
            }
        }