void InitializeRecorder() { var audioSession = AVAudioSession.SharedInstance(); var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("audioSession: {0}", err); return; } err = audioSession.SetActive(true); if (error != null) { Console.WriteLine("audioSession: {0}", err); return; } var localStorage = PCLStorage.FileSystem.Current.LocalStorage.Path; string audioFilePath = localStorage + "/Todo.wav"; Console.WriteLine("Audio file path: " + audioFilePath); url = NSUrl.FromFilename(audioFilePath); var values = new NSObject[] { NSNumber.FromFloat(8000.0f), // Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), // AVFormat NSNumber.FromInt32(1), // Channels NSNumber.FromInt32(16), // PCMBitDepth NSNumber.FromBoolean(false), // IsBigEndianKey NSNumber.FromBoolean(false) // IsFloatKey }; var keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; settings = NSDictionary.FromObjectsAndKeys(values, keys); recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error); recorder.PrepareToRecord(); }
bool PrepareAudioRecording() { //Declare string for application temp path and tack on the file extension string fileName = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss")); string tempRecording = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), fileName); Console.WriteLine(tempRecording); this.audioFilePath = NSUrl.FromFilename(tempRecording); var audioSettings = new AudioSettings() { SampleRate = 44100.0f, Format = AudioFormatType.MPEG4AAC,//MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC, NumberChannels = 1, AudioQuality = AVAudioQuality.High }; //Set recorder parameters NSError error; recorder = AVAudioRecorder.Create(this.audioFilePath, audioSettings, out error); if ((recorder == null) || (error != null)) { Console.WriteLine(error); return(false); } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord()) { recorder.Dispose(); recorder = null; return(false); } recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e) { recorder.Dispose(); recorder = null; Console.WriteLine("Done Recording (status: {0})", e.Status); }; return(true); }
private void StartRecord() { if (!isRecording) { PerformSegue("showPopover", null); l_Result.Text = "結果"; iv_ResultFrogImage.Image = null; var DocUrl = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string FileName = "Frog.wav"; string FilePath = System.IO.Path.Combine(DocUrl, FileName); var url = new NSUrl(FilePath); NSError error = AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord); if (error != null) { Console.WriteLine(error.LocalizedDescription); } var settings = new AudioSettings() { Format = AudioToolbox.AudioFormatType.LinearPCM, NumberChannels = 2, EncoderAudioQualityForVBR = AVAudioQuality.Max, SampleRate = 44100f, LinearPcmBitDepth = 16, LinearPcmBigEndian = true, LinearPcmFloat = true }; audioRecorder = AVAudioRecorder.Create(url, settings, out error); if (error != null) { audioRecorder = null; Console.WriteLine(error.LocalizedDescription); } else { audioRecorder.Delegate = new MyAVAudioRecorderDelegate(this); audioRecorder.PrepareToRecord(); audioRecorder.Record(); bt_Record.SetImage(UIImage.FromBundle("recordingbtn"), UIControlState.Normal); isRecording = true; } } }
private static void StartRecording() { audioRecorder.PrepareToRecord(); audioRecorder.Record(); audioPlayer = null; var actionSheet = new UIActionSheet(TouchFactory.Instance.GetResourceString("Recording")) { TouchFactory.Instance.GetResourceString("StopRecording"), }; actionSheet.Style = UIActionSheetStyle.BlackTranslucent; actionSheet.ShowInView(TouchFactory.Instance.TopViewController.View); actionSheet.Dismissed += delegate(object sender, UIButtonEventArgs args) { DoneRecording(); }; }
private void prepareToRecord() { if (_audioSessionCreated) { //Declare string for application temp path and tack on the file extension _audioFileName = string.Format("{0}{1}.wav", _songName, DateTime.Now.ToString("yyyyMMddHHmmss")); _audioFilePath = Path.Combine(Path.GetTempPath(), _audioFileName); Console.WriteLine("Audio File Path: " + _audioFilePath); _url = NSUrl.FromFilename(_audioFilePath); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), //Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat NSNumber.FromInt32(2), //Channels NSNumber.FromInt32(16), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary _settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters _recorder = AVAudioRecorder.Create(_url, new AudioSettings(_settings), out _error); //Set Recorder to Prepare To Record _recorder.PrepareToRecord(); } }
private void RecordingButtonAction(object item, EventArgs args) { if (m_isRecording == false) { m_isRecording = true; //UI Update { this.ShowNavigationButton(false); m_recordButton.TintColor = RecordingTintColor; m_playButton.Enabled = false; m_trashButton.Enabled = false; } if (File.Exists(m_recordingFilePath)) { File.Delete(m_recordingFilePath); } m_oldSessionCategory = AVAudioSession.SharedInstance().Category; AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Record); m_audioRecorder.PrepareToRecord(); m_audioRecorder.Record(); } else { m_isRecording = false; //UI Update { this.ShowNavigationButton(true); m_recordButton.TintColor = NormalTintColor; m_playButton.Enabled = true; m_trashButton.Enabled = true; } m_audioRecorder.Stop(); AVAudioSession.SharedInstance().SetCategory(new NSString(m_oldSessionCategory)); } }
bool PrepareAudioRecording() { //Declare string for application temp path and tack on the file extension //string fileName = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss")); string fileName = "temp.aac"; string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName; this.audioFilePath = NSUrl.FromFilename(tempRecording); var audioSettings = new AudioSettings() { SampleRate = 44100.0f, Format = MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC, NumberChannels = 1, AudioQuality = AVAudioQuality.High }; //Set recorder parameters NSError error; recorder = AVAudioRecorder.Create(this.audioFilePath, audioSettings, out error); if ((recorder == null) || (error != null)) { return(false); } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord()) { recorder.Dispose(); recorder = null; return(false); } recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e) { recorder.Dispose(); recorder = null; }; recorder.MeteringEnabled = true; return(true); }
protected void PrepareAudioRecording() { //Declare string for application temp path and tack on the file extension string fileName = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss")); string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName; Console.WriteLine(tempRecording); this.audioFilePath = NSUrl.FromFilename(tempRecording); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters NSError error; recorder = AVAudioRecorder.ToUrl(this.audioFilePath, settings, out error); if (recorder == null) { Console.WriteLine(error); return; } //Set Recorder to Prepare To Record recorder.PrepareToRecord(); }
public void StartRecording(string fileName) { InitializeAudioSession(); _fileName = fileName + ".wav"; _fullFilePath = Path.Combine(Path.GetTempPath(), _fileName); Console.WriteLine("Audio File Path: " + _fullFilePath); _url = NSUrl.FromFilename(_fullFilePath); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = { NSNumber.FromFloat(44100.0f), //Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat NSNumber.FromInt32(2), //Channels NSNumber.FromInt32(16), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary _settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters _recorder = AVAudioRecorder.Create(_url, new AudioSettings(_settings), out _); _recorder.PrepareToRecord(); _recorder.Record(); }
protected override RecordingResult NativeStartRecording(string fileName) { var documentsPath = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true); var path = $"{documentsPath[0]}/{fileName}.caf"; var soundFileURL = new NSUrl(path); NSError error; AudioRecorder = AVAudioRecorder.Create(soundFileURL, audioSettings, out error); if (AudioRecorder == null) { Mvx.Trace(MvxTraceLevel.Error, "Error trying to create AVAudioRecorder. Got Exception: {0}", error.ToString()); return(false); } AudioRecorder.PrepareToRecord(); AudioRecorder.Record(); return(new RecordingResult(true, path)); }
private bool PrepareAudioRecording() { var result = false; audioFilePath = CreateOutputUrl(); var audioSettings = new AudioSettings { SampleRate = 44100, NumberChannels = 1, AudioQuality = AVAudioQuality.High, Format = AudioToolbox.AudioFormatType.MPEG4AAC, }; // Set recorder parameters recorder = AVAudioRecorder.Create(audioFilePath, audioSettings, out NSError error); if (error == null) { // Set Recorder to Prepare To Record if (!recorder.PrepareToRecord()) { recorder.Dispose(); recorder = null; } else { recorder.FinishedRecording += OnFinishedRecording; result = true; } } else { Console.WriteLine(error.LocalizedDescription); } return(result); }
public async Task <bool> BeginCaptureAudio() { var tcs = new TaskCompletionSource <bool> (); AVAudioSession.SharedInstance().RequestRecordPermission(granted => tcs.TrySetResult(granted)); if (!await tcs.Task) { return(false); } AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Record); AVAudioSession.SharedInstance().SetActive(true); NSError error; var settings = new AudioSettings { Format = AudioFormatType.LinearPCM, SampleRate = 8000, NumberChannels = 1, LinearPcmBitDepth = 16, LinearPcmFloat = false, LinearPcmBigEndian = false, }; var recordFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav"); _audioRecorder = AVAudioRecorder.Create(NSUrl.FromFilename(recordFile), settings, out error); if (_audioRecorder != null && _audioRecorder.PrepareToRecord()) { _audioRecorder.Record(); } else { _audioRecorder = null; return(false); } return(true); }
public override void ViewDidLoad() { base.ViewDidLoad(); var url = new NSUrl("/dev/null"); var settings = new AudioSettings { SampleRate = 44100, Format = AudioFormatType.AppleLossless, NumberChannels = 2, EncoderAudioQualityForVBR = AVAudioQuality.Min }; NSError err; _recorder = AVAudioRecorder.Create(url, settings, out err); if (err != null) { Debug.WriteLine("Ups, could not create recorder, {0}", err); return; } err = AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Debug.WriteLine("Error setting category : {0}", err); } _recorder.PrepareToRecord(); _recorder.MeteringEnabled = true; _recorder.Record(); var displayLink = CADisplayLink.Create(UpdateMeters); displayLink.AddToRunLoop(NSRunLoop.Current, NSRunLoopMode.Common); }
public static void StartRecording(string FileName) { NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)AudioFormatType.LinearPCM), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys); NSUrl url = NSUrl.FromFilename(FileName); // Set recorder parameters NSError error; _recorder = AVAudioRecorder.ToUrl(url, settings, out error); if (_recorder == null) { Console.WriteLine(error); return; } // Set Metering Enabled so you can get the time of the wav file _recorder.MeteringEnabled = true; _recorder.PrepareToRecord(); _recorder.Record(); }
public bool PrepareAudioRecording() { // You must initialize an audio session before trying to record var audioSession = AVAudioSession.SharedInstance(); var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("audioSession: {0}", err); return(false); } err = audioSession.SetActive(true); if (err != null) { Console.WriteLine("audioSession: {0}", err); return(false); } // Declare string for application temp path and tack on the file extension string fileName = string.Format("recording{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss")); string tempRecording = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine(tempRecording); audioFilePath = NSUrl.FromFilename(tempRecording); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters NSError error; recorder = AVAudioRecorder.Create(this.audioFilePath, new AudioSettings(settings), out error); if ((recorder == null) || (error != null)) { Console.WriteLine(error); return(false); } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord()) { recorder.Dispose(); recorder = null; return(false); } recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e) { recorder.Dispose(); recorder = null; Console.WriteLine("Done Recording (status: {0})", e.Status); }; return(true); }
bool PrepareAudioRecording() { //Declare string for application temp path and tack on the file extension string fileName = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss")); string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName; Console.WriteLine(tempRecording); this.audioFilePath = NSUrl.FromFilename(tempRecording); var audioSettings = new AudioSettings() { SampleRate = 44100.0f, Format = MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC, NumberChannels = 1, AudioQuality = AVAudioQuality.High }; //Set recorder parameters NSError error; recorder = AVAudioRecorder.Create(this.audioFilePath, audioSettings, out error); if ((recorder == null) || (error != null)) { Console.WriteLine(error); return false; } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord()) { recorder.Dispose(); recorder = null; return false; } recorder.FinishedRecording += delegate (object sender, AVStatusEventArgs e) { recorder.Dispose(); recorder = null; Console.WriteLine("Done Recording (status: {0})", e.Status); }; return true; }
public void StartRecording(string path) { try { path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), path); // this line is added to place file in iOS temp directory, may not be required in Halza app var audioSession = AVAudioSession.SharedInstance(); audioSession.RequestRecordPermission(delegate(bool granted) { if (granted) { var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("audioSession: {0}", err); } err = audioSession.SetActive(true); if (err != null) { Console.WriteLine("audioSession: {0}", err); } url = NSUrl.FromFilename(path); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(16000), //Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat //NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat NSNumber.FromInt32(2), //Channels NSNumber.FromInt32(16), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error); //Set Recorder to Prepare To Record recorder.PrepareToRecord(); recorder.Record(); } }); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public bool InitializeRecordService(string path = "") { var audioSession = AVAudioSession.SharedInstance(); var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("audioSession: {0}", err); return(false); } err = audioSession.SetActive(true); if (err != null) { Console.WriteLine("audioSession: {0}", err); return(false); } //Declare string for application temp path and tack on the file extension if (path.Length == 0) { path = Path.GetTempPath(); } string fileName = string.Format("audio{0}.wav", DateTime.Now.ToString("yyyyMMddHHmmss")); string audioFilePath = Path.Combine(path, fileName); Console.WriteLine("Audio File Path: " + audioFilePath); _path = audioFilePath; _url = NSUrl.FromFilename(audioFilePath); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), //Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat NSNumber.FromInt32(2), //Channels NSNumber.FromInt32(16), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary _settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters _recorder = AVAudioRecorder.Create(_url, new AudioSettings(_settings), out _error); //Set Recorder to Prepare To Record return(_recorder.PrepareToRecord()); }
public void StartRecording() { NSError error; var audioSession = AVAudioSession.SharedInstance(); var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("audioSession: {0}", err); return; } err = audioSession.SetActive(true); if (err != null) { Console.WriteLine("audioSession: {0}", err); return; } var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var temp = Path.Combine(documents, "..", "tmp"); _recordedFileName = Path.Combine(temp, Guid.NewGuid() + ".mp4"); using (var url = new NSUrl(_recordedFileName)) { //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary var values = new NSObject[] { NSNumber.FromFloat(44100.0f), //Sample Rate NSNumber.FromInt32((int) AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat NSNumber.FromInt32(2), //Channels NSNumber.FromInt32(16), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary var keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary var settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters _recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error); } //Set Recorder to Prepare To Record _recorder.PrepareToRecord(); _recorder.Record(); }
public OperationResult Initialize(string audioFilePath, float sampleRate = 44100, int channels = 2, int bitDepth = 16) { if (string.IsNullOrEmpty(audioFilePath)) { return(OperationResult.AsFailure("Invalid audio file path specified")); } var audioSession = AVAudioSession.SharedInstance(); var error = audioSession.SetCategory(AVAudioSessionCategory.Record); if (error != null) { return(OperationResult.AsFailure(error.LocalizedDescription)); } error = audioSession.SetActive(true); if (error != null) { return(OperationResult.AsFailure(error.LocalizedDescription)); } var url = NSUrl.FromFilename(audioFilePath); NSObject[] values = new NSObject[] { NSNumber.FromFloat(sampleRate), //Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat NSNumber.FromInt32(channels), //Channels NSNumber.FromInt32(bitDepth), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; _settings = NSDictionary.FromObjectsAndKeys(values, keys); _recorder = AVAudioRecorder.Create(url, new AudioSettings(_settings), out error); if (error != null) { return(OperationResult.AsFailure("Error creating audio file: " + error.LocalizedDescription)); } _recorder.MeteringEnabled = true; var success = _recorder.PrepareToRecord(); if (success) { return(OperationResult.AsSuccess()); } else { return(OperationResult.AsFailure("Could not initialize recorder")); } }
bool PrepareAudioRecording () { audioFilePath = CreateOutputUrl (); var audioSettings = new AudioSettings { SampleRate = 44100, Format = AudioToolbox.AudioFormatType.MPEG4AAC, NumberChannels = 1, AudioQuality = AVAudioQuality.High }; //Set recorder parameters NSError error; recorder = AVAudioRecorder.Create (audioFilePath, audioSettings, out error); if (error != null) { Console.WriteLine (error); return false; } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord ()) { recorder.Dispose (); recorder = null; return false; } recorder.FinishedRecording += OnFinishedRecording; return true; }
/// /// Name AudioRecordStart /// /// <summary> Start the recorder to record the audio. /// </summary> /// public void AudioRecordStart() { try { string fileName = string.Format("Myfile{0}.wav", DateTime.Now.ToString("yyyyMMddHHmmss")); audioFilePath = Path.Combine(Path.GetTempPath(), fileName); url = NSUrl.FromFilename(audioFilePath); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat (44100.0f), //Sample Rate NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat NSNumber.FromInt32 (2), //Channels NSNumber.FromInt32 (16), //PCMBitDepth NSNumber.FromBoolean (false), //IsBigEndianKey NSNumber.FromBoolean (false) //IsFloatKey }; NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)AudioFormatType.LinearPCM), NSNumber.FromInt32(2), }; NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, }; settings = NSDictionary.FromObjectsAndKeys(values, keys); recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error); recorder.PrepareToRecord(); recorder.Record(); AddNewAudioView.Playevent.Invoke(); } catch (Exception ex) { LogTracking.LogTrace(ex.ToString()); } }
public bool StartRecord(ref string errMsg, ref string audioFilePath) { if (!Init(ref errMsg)) { return(false); } //Declare string for application temp path and tack on the file extension string fileName = string.Format("Myfile{0}.wav", DateTime.Now.ToString("yyyyMMddHHmmss")); audioFilePath = Path.Combine(Path.GetTempPath(), fileName); Console.WriteLine("Audio File Path: " + audioFilePath); url = NSUrl.FromFilename(audioFilePath); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { //Sample Rate NSNumber.FromFloat(44100.0f), //AVFormat NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //Channels NSNumber.FromInt32(2), //PCMBitDepth NSNumber.FromInt32(16), //IsBigEndianKey NSNumber.FromBoolean(false), //IsFloatKey NSNumber.FromBoolean(false) }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys); if (IsDevice()) { //Set recorder parameters recorder = AVAudioRecorder.Create(url, GetSettings_device_02(), out error); } else { //Set recorder parameters recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error); } if (error != null) { Console.WriteLine("M Love: " + error.Description); } bool isPrepared = recorder.PrepareToRecord(); if (isPrepared) { recorder.Record(); return(true); } return(false); }
public override async void ViewDidLoad() { base.ViewDidLoad(); fileName = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".m4a"; if (!createMode) { if (thisTask == null || thisActivity == null) { AppUtils.ShowSimpleDialog(this, "ERROR", "Error loading task data", "Ok"); NavigationController.PopViewController(true); return; } TaskDescriptionLabel.Text = thisTask.Description; folderName = Common.LocalData.Storage.GetCacheFolder(thisActivity.Id.ToString()); } else { // set up for recording to 'listen to audio' tasks folderName = Common.LocalData.Storage.GetCacheFolder("created"); } filePath = Path.Combine(folderName, fileName); // Sanity check for permissions - if we're here, it should be safe bool hasPerm = await AppUtils.AuthorizeMic(); if (!hasPerm) { AppUtils.ShowSimpleDialog(this, "Requires Microphone", "Please grant OurPlace microphone access in the system settings to record audio clips!", "Ok"); NavigationController.PopViewController(true); return; } // Set up audio recording session audioSession = AVAudioSession.SharedInstance(); NSError err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("ERROR setting up audio session: " + err.LocalizedDescription); return; } err = audioSession.SetActive(true); if (err != null) { Console.WriteLine("ERROR activating audio session: " + err.LocalizedDescription); return; } //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(16000.0f), //Sample Rate NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat NSNumber.FromInt32(1), //Channels NSNumber.FromInt32(16), //PCMBitDepth NSNumber.FromBoolean(false), //IsBigEndianKey NSNumber.FromBoolean(false) //IsFloatKey }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVLinearPCMBitDepthKey, AVAudioSettings.AVLinearPCMIsBigEndianKey, AVAudioSettings.AVLinearPCMIsFloatKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys); //Set recorder parameters recorder = AVAudioRecorder.Create(NSUrl.FromFilename(filePath), new AudioSettings(settings), out error); recorder.PrepareToRecord(); }
private bool PrepareAudioRecording() { var audioSession = AVAudioSession.SharedInstance(); var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord); if (err != null) { Console.WriteLine("audioSession: {0}", err); return(false); } err = audioSession.SetActive(true); if (err != null) { Console.WriteLine("audioSession: {0}", err); return(false); } NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; var settings = NSDictionary.FromObjectsAndKeys(values, keys); NSError error; var _url = NSUrl.FromFilename(Constants.INITIAL_AUDIO_FILE_PATH); _audioRecorder = AVAudioRecorder.Create(_url, new AudioSettings(settings), out error); if ((_audioRecorder == null) || (error != null)) { Console.WriteLine(error); return(false); } if (!_audioRecorder.PrepareToRecord()) { _audioRecorder.Dispose(); _audioRecorder = null; return(false); } _audioRecorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e) { _audioRecorder.Dispose(); _audioRecorder = null; Console.WriteLine("Done Recording (status: {0})", e.Status); }; return(true); }
bool PrepareAudioRecording () { //Declare string for application temp path and tack on the file extension string fileName = string.Format ("Myfile{0}.aac", DateTime.Now.ToString ("yyyyMMddHHmmss")); string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName; Console.WriteLine (tempRecording); this.audioFilePath = NSUrl.FromFilename(tempRecording); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys (values, keys); //Set recorder parameters NSError error; recorder = AVAudioRecorder.ToUrl(this.audioFilePath, settings, out error); if ((recorder == null) || (error != null)) { Console.WriteLine (error); return false; } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord ()) { recorder.Dispose (); recorder = null; return false; } recorder.FinishedRecording += delegate (object sender, AVStatusEventArgs e) { recorder.Dispose (); recorder = null; Console.WriteLine ("Done Recording (status: {0})", e.Status); }; return true; }
public static void StartRecording(string FileName) { NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)AudioFormatType.LinearPCM), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; NSDictionary settings = NSDictionary.FromObjectsAndKeys (values, keys); NSUrl url = NSUrl.FromFilename(FileName); // Set recorder parameters NSError error; _recorder = AVAudioRecorder.ToUrl (url, settings, out error); if (_recorder == null){ Console.WriteLine (error); return; } // Set Metering Enabled so you can get the time of the wav file _recorder.MeteringEnabled = true; _recorder.PrepareToRecord(); _recorder.Record(); }
bool PrepareAudioRecording() { // You must initialize an audio session before trying to record var audioSession = AVAudioSession.SharedInstance (); var err = audioSession.SetCategory (AVAudioSessionCategory.PlayAndRecord); if(err != null) { Console.WriteLine ("audioSession: {0}", err); return false; } err = audioSession.SetActive (true); if(err != null ){ Console.WriteLine ("audioSession: {0}", err); return false; } // Declare string for application temp path and tack on the file extension string fileName = string.Format ("Myfile{0}.aac", DateTime.Now.ToString ("yyyyMMddHHmmss")); string tempRecording = Path.Combine (Path.GetTempPath (), fileName); Console.WriteLine (tempRecording); this.audioFilePath = NSUrl.FromFilename(tempRecording); //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary NSObject[] values = new NSObject[] { NSNumber.FromFloat(44100.0f), NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), NSNumber.FromInt32(1), NSNumber.FromInt32((int)AVAudioQuality.High) }; //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary NSObject[] keys = new NSObject[] { AVAudioSettings.AVSampleRateKey, AVAudioSettings.AVFormatIDKey, AVAudioSettings.AVNumberOfChannelsKey, AVAudioSettings.AVEncoderAudioQualityKey }; //Set Settings with the Values and Keys to create the NSDictionary settings = NSDictionary.FromObjectsAndKeys (values, keys); //Set recorder parameters NSError error; recorder = AVAudioRecorder.Create(this.audioFilePath, new AudioSettings(settings), out error); if ((recorder == null) || (error != null)) { Console.WriteLine (error); return false; } //Set Recorder to Prepare To Record if (!recorder.PrepareToRecord ()) { recorder.Dispose (); recorder = null; return false; } recorder.FinishedRecording += delegate (object sender, AVStatusEventArgs e) { recorder.Dispose (); recorder = null; Console.WriteLine ("Done Recording (status: {0})", e.Status); }; return true; }