コード例 #1
0
        public MainPage(App app)
        {
            _mainpage = this;
            InitializeComponent();

            ScrollView.Content = Label;

            SetButtonImage("listen_disabled_allgreyedout.png");
            //SetActionButtonIsEnabled(false);

            //ImageButton.Clicked += ActionButton_ButtonClicked;
            //ImageButton.Pressed += ImageButton_PressedAsync;
            _sapService = new SapService(OnConnectedCallback);

            Task.Run(async() => await _sapService.Connect().ConfigureAwait(false));

            Task.Run(() =>
            {
                Pref = new Preferences(app, this);
                Pref.LoadSettings();

                _player = new Player();
                _player.SetSource(new MediaBufferSource(File.ReadAllBytes(Path.Combine(imageDir, "ding.mp3"))));
                _player.PrepareAsync();
                _player.PlaybackCompleted += delegate { _player.Stop(); };
            }
                     );
        }
コード例 #2
0
ファイル: AudioRecorder.cs プロジェクト: cybernetic87/GAssist
        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();
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: AudioRecorder.cs プロジェクト: cybernetic87/GAssist
        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);
        }