Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DelegateCommand PlayCommand { get; private set; }
- public DelegateCommand StopCommand { get; private set; }
- public DelegateCommand RecordCommand { get; private set; }
- public DelegateCommand PauseCommand { get; private set; }
- private AudioGraph audioGraph;
- private DeviceInformation selectedDevice;
- private TimeSpan duration;
- private TimeSpan position;
- private AudioFileOutputNode fileOutputNode;
- private AudioFileInputNode fileInputNode;
- private AudioDeviceOutputNode deviceOutputNode;
- private AudioDeviceInputNode deviceInputNode;
- private async void Record()
- {
- if (audioGraph == null)
- {
- var settings = new AudioGraphSettings(AudioRenderCategory.Media);
- settings.EncodingProperties = recordingFormat.Audio;
- var res = await AudioGraph.CreateAsync(settings);
- if (res.Status != AudioGraphCreationStatus.Success)
- {
- Diagnostics += $"Audio Graph Creation Error: {res.Status}rn";
- return;
- }
- audioGraph = res.Graph;
- audioGraph.UnrecoverableErrorOccurred += OnAudioGraphError;
- }
- if (deviceInputNode == null)
- {
- var res = await audioGraph.CreateDeviceInputNodeAsync(MediaCategory.Speech,
- recordingFormat.Audio, SelectedInputDevice);
- // if you get AudioDeviceNodeCreationStatus.AccessDenied -
- //remember to add microphone capabilities
- if (res.Status != AudioDeviceNodeCreationStatus.Success)
- {
- Diagnostics += $"Device Input Node Error: {res.Status}rn";
- return;
- }
- deviceInputNode = res.DeviceInputNode;
- }
- var outputStorageFile = await SelectOutputFile();
- if (outputStorageFile != null)
- {
- var res = await audioGraph.CreateFileOutputNodeAsync(
- outputStorageFile, recordingFormat);
- if (res.Status != AudioFileNodeCreationStatus.Success)
- {
- Diagnostics += $"Output File Error: {res.Status}rn";
- return;
- }
- fileOutputNode = res.FileOutputNode;
- // construct the graph
- deviceInputNode.AddOutgoingConnection(fileOutputNode);
- }
- audioGraph.Start();
- EnableCommands(true);
- Diagnostics += "Started recordingrn";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement