示例#1
0
        void Play_TouchUpInside(object sender, EventArgs e)
        {
            OutputLabel.Text = $"Playing";

            var os = new MemoryStream();

            if (_options.StreamFormat == AudioRecordOptions.Format.Flac)
            {
                using (var fs = new MemoryStream(bytes))
                {
                    using (var f = new FlacBox.WaveOverFlacStream(fs, FlacBox.WaveOverFlacStreamMode.Decode, false))
                    {
                        f.CopyTo(os);
                        os.Seek(0, SeekOrigin.Begin);
                    }
                }
            }
            else
            {
                os = new MemoryStream(bytes);
            }

            using (var data = NSData.FromStream(os))
            {
                PlayData(data);
            }
        }
示例#2
0
        async void Start_Click(object sender, System.EventArgs e)
        {
            if (_recorder != null)
            {
                return;
            }

            _recorder = new AndroidAudioRecorder();
            var result = await _recorder.Record(_options);

            _output.Text = $"Recorded {result.AudioBytes.Length} bytes";

            // playback file
            _tmpFile = File.CreateTempFile("TCL", "wav", CacheDir);
            _tmpFile.DeleteOnExit();

            if (_options.StreamFormat == AudioRecordOptions.Format.Wave)
            {
                var fos = new FileOutputStream(_tmpFile);
                fos.Write(result.AudioBytes);
                fos.Close();
            }
            else
            {
                using (var ms = new System.IO.MemoryStream(result.AudioBytes))
                {
                    using (var fos = System.IO.File.OpenWrite(_tmpFile.AbsolutePath))
                    {
                        using (var f = new FlacBox.WaveOverFlacStream(ms, FlacBox.WaveOverFlacStreamMode.Decode, false))
                        {
                            f.CopyTo(fos);
                        }
                    }
                }
            }

            _recorder = null;
        }