Posts

Showing posts with the label streamwriter

Xamarin.Android and RecordAudio: how to combine file writing and other task

Xamarin.Android and RecordAudio: how to combine file writing and other task I develop a Xamarin.Android app where I need to record an audio file in a .wav and to display the related spectrogram in the same time. I'm able to perform the 2 tasks separately but not to combine them. I use an AudioRecord to record the sound through the microphone: AudioRecord public async Task StartRecording() { audioRecord = new AudioRecord(AudioSource.Mic, 44100, ChannelIn.Mono, Android.Media.Encoding.Pcm16bit, bufferSize); if (audioRecord.State == State.Initialized) audioRecord.StartRecording(); isRecording = true; recordingThread = new System.Threading.Thread(new ThreadStart( WriteAudioDataToFile )); recordingThread.Start(); } The file writing is done in WriteAudioDataToFile() and works fine: WriteAudioDataToFile() private void WriteAudioDataToFile() { byte data = new byte[bufferSize]; string filename = GetTempFilename(); FileOutputStr...