Exemplo n.º 1
0
        private async void Button_CreateBook_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ASR_Recog.Release();

                //GlobalData.TalkingPageViewModel.Test();

                //GlobalData.TalkingPageViewModel.IsOpenVoiceConversion = !GlobalData.TalkingPageViewModel.IsOpenVoiceConversion;
                //GlobalData.TalkingPageViewModel.IsPartySpeeking = !GlobalData.TalkingPageViewModel.IsPartySpeeking;
                GlobalData.TalkingPageViewModel.SetTalkingState(ViewModel.Enum.TalkState.CreateingBook);
                this.StarkPanel_CreateLawbook.Visibility = Visibility.Visible;
                this.Grid_Mask.Visibility  = Visibility.Visible;
                this.Grid_Video.Visibility = Visibility.Collapsed;

                await Task.Delay(TimeSpan.FromSeconds(1));

                if (_homeWindow.Frame_BusinessPage.CanGoBack)
                {
                    _homeWindow.Frame_BusinessPage.RemoveBackEntry();
                }

                _homeWindow.Frame_BusinessPage.NavigationUIVisibility = System.Windows.Navigation.NavigationUIVisibility.Hidden;
                _homeWindow.Grid_MainNavigationButtons.Visibility     = Visibility.Collapsed;
                _homeWindow.Frame_BusinessPage.Navigate(new Uri("Pages/LawBookPage.xaml", UriKind.Relative));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        private void TalkingPage_Loaded(object sender, RoutedEventArgs e)
        {
            GlobalData.TalkingPageViewModel.SetTalkingState(ViewModel.Enum.TalkState.None);

            _cameraHelperFont.IsStartPicture = true;
            _cameraHelperFont.IsDisplay      = true;
            _cameraHelperFont.SourcePlayer   = VideoSourcePlayer_Front;
            _cameraHelperFont.UpdateCameraDevices();

            if (_cameraHelperFont.CameraDevices.Count > 0)
            {
                string videoFullPath   = $"{AppDomain.CurrentDomain.BaseDirectory}InquiryData\\{GlobalData.NewTalkViewModel.Inquiry.InquiryId}\\front.mp4";
                string pictureFullPath = $"{AppDomain.CurrentDomain.BaseDirectory}InquiryData\\{GlobalData.NewTalkViewModel.Inquiry.InquiryId}\\mainpic.jpg";

                _cameraHelperFont.SetCameraDevice(0, videoFullPath, pictureFullPath, true, true, System.Drawing.RotateFlipType.RotateNoneFlipX);

                GlobalData.NewTalkViewModel.Inquiry.InquiryVideo1FilePath  = videoFullPath;
                GlobalData.NewTalkViewModel.Inquiry.InquiryPictureFilePath = pictureFullPath;
            }

            _cameraHelperBack.IsDisplay    = true;
            _cameraHelperBack.SourcePlayer = VideoSourcePlayer_Back;
            _cameraHelperBack.UpdateCameraDevices();

            if (_cameraHelperBack.CameraDevices.Count > 1)
            {
                string videoFullPath   = $"{AppDomain.CurrentDomain.BaseDirectory}InquiryData\\{GlobalData.NewTalkViewModel.Inquiry.InquiryId}\\back.mp4";
                string pictureFullPath = $"{AppDomain.CurrentDomain.BaseDirectory}InquiryData\\{GlobalData.NewTalkViewModel.Inquiry.InquiryId}\\mainpic.jpg";

                //_cameraHelperBack.SetCameraDevice(1, videoFullPath, string.Empty, true, false, System.Drawing.RotateFlipType.RotateNoneFlipX);
                _cameraHelperBack.SetCameraDevice(1, videoFullPath, pictureFullPath, true, true, System.Drawing.RotateFlipType.RotateNoneFlipX);

                GlobalData.NewTalkViewModel.Inquiry.InquiryVideo2FilePath = videoFullPath;
            }

            int t = ASR_Recog.Init();

            if (t >= 0)
            {
                _isVoiceReady = true;
                _dataQueue    = new ConcurrentQueue <byte[]>();

                _voiceThread = new Thread(new ThreadStart(this.StartRecog));
                _voiceThread.IsBackground = true;
            }

            _homeWindow = (Window.GetWindow(this) as HomeWindow);
        }
Exemplo n.º 3
0
        private void StartRecog()
        {
            while (true)
            {
                if (this._dataQueue.IsEmpty)
                {
                    Thread.Sleep(100);
                }
                else
                {
                    byte[] dataTmp = (byte[])null;
                    if (!this._dataQueue.TryDequeue(out dataTmp))
                    {
                        Thread.Sleep(100);
                    }
                    else
                    {
                        int ASRRealTimeEnd = 0;
                        if (ASR_Recog.GetRealtime() == "yes")
                        {
                            string str_t = ASR_Recog.RealtimeRecog(dataTmp, dataTmp.Length, out ASRRealTimeEnd);
                            Dispatcher.BeginInvoke((Action) delegate()
                            {
                                this.TextBox_CurrentTalkingCountent.AppendText(str_t);
                            });
                        }
                        //this.memoEdit2.BeginInvoke((Delegate)(() => this.memoEdit2.Text += ASR_Recog.RealtimeRecog(dataTmp, dataTmp.Length, out ASRRealTimeEnd)));
                        else if (ASR_Recog.GetRealtime() == "rt")
                        {
                            string result = ASR_Recog.RealtimeRecog(dataTmp, dataTmp.Length, out ASRRealTimeEnd);

                            VoiceConverterModel voiceConverterModel_t = JsonHelper.DeserializeObjectFromJson <VoiceConverterModel>(result);
                            if (voiceConverterModel_t == null)
                            {
                                continue;
                            }

                            Dispatcher.BeginInvoke((Action) delegate()
                            {
                                this.TextBox_CurrentTalkingCountent.Text = _lastRealContent;
                                for (int i = 0; i < voiceConverterModel_t.SegmentCount; i++)
                                {
                                    this.TextBox_CurrentTalkingCountent.Text = this.TextBox_CurrentTalkingCountent.Text + voiceConverterModel_t.Segment[i].Text;
                                }

                                this.Button_Submit.IsEnabled = false;
                                this.TextBox_CurrentTalkingCountent.SelectionStart = this.TextBox_CurrentTalkingCountent.Text.Length;
                            });
                            //this.memoEdit2.BeginInvoke((Delegate)(() => this.ParseJson(result)));
                            if (ASRRealTimeEnd == 1)
                            {
                                //this.memoEdit2.BeginInvoke((Delegate)(() => this.last_content_ = this.memoEdit2.Text));

                                Dispatcher.BeginInvoke((Action) delegate()
                                {
                                    for (int i = 0; i < voiceConverterModel_t.SegmentCount; i++)
                                    {
                                        this.TextBox_CurrentTalkingCountent.Text = _lastRealContent + voiceConverterModel_t.Segment[i].Text;
                                    }

                                    _lastRealContent = this.TextBox_CurrentTalkingCountent.Text;
                                    this.TextBox_CurrentTalkingCountent.SelectionStart = this.TextBox_CurrentTalkingCountent.Text.Length;
                                    this.Button_Submit.IsEnabled = true;
                                });
                            }
                        }
                    }
                }
            }
        }