Exemplo n.º 1
0
        public static void StartRecording(bool htmlResponse)
        {
            //_audioCapture = new AudioCapture(16000, AudioChannel.Mono, AudioSampleType.S16Le);
            IsRecording = true;

            var ar = new AssistRequest
            {
                Config = new AssistConfig
                {
                    AudioInConfig = new AudioInConfig
                    {
                        SampleRateHertz = 16000,
                        Encoding        = AudioInConfig.Types.Encoding.Linear16
                    },
                    ScreenOutConfig = new ScreenOutConfig
                    {
                        ScreenMode = htmlResponse
                            ? ScreenOutConfig.Types.ScreenMode.Playing
                            : ScreenOutConfig.Types.ScreenMode.Unspecified
                    }
                }
            };

            SapService.SendData(ar.ToByteArray());

            _audioCapture.Prepare();
            Record();
        }
Exemplo n.º 2
0
        public void Stop()
        {
            var ar = new AssistRequest
            {
                Config = new AssistConfig
                {
                    AudioInConfig = new AudioInConfig
                    {
                        SampleRateHertz = 16000,
                        Encoding        = AudioInConfig.Types.Encoding.Flac
                    }
                }
            };

            SapService.SendData(ar.ToByteArray());

            IsPlaying  = false;
            IsPrepared = false;
            if (_player.State != PlayerState.Playing)
            {
                return;
            }
            _player.Stop();

            _source.Cancel();
            BufferFileStream.Close();

            //if (File.Exists(BufferFilePath)) File.Delete(BufferFilePath);
            _player.PlaybackCompleted -= Player_PlaybackCompleted;
            OnPlaybackStopped(EventArgs.Empty);

            MainPage.SetButtonImage("listen_blue.png");
            MainPage.SetActionButtonIsEnabled(true);
        }
Exemplo n.º 3
0
        private static void Record()
        {
            _source = new CancellationTokenSource();
            _token  = _source.Token;


            Task.Run(() =>
            {
                while (!_token.IsCancellationRequested)
                {
                    var ar2 = new AssistRequest
                    {
                        AudioIn = ByteString.CopyFrom(_audioCapture.Read(_bufferSize))
                    };
                    SapService.SendData(ar2.ToByteArray());
                }

                _audioCapture.Flush();
                _audioCapture.Unprepare();
            }, _token);
        }