Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. public DelegateCommand PlayCommand { get; private set; }
  2. public DelegateCommand StopCommand { get; private set; }
  3. public DelegateCommand RecordCommand { get; private set; }
  4. public DelegateCommand PauseCommand { get; private set; }
  5.  
  6. private AudioGraph audioGraph;
  7. private DeviceInformation selectedDevice;
  8. private TimeSpan duration;
  9. private TimeSpan position;
  10. private AudioFileOutputNode fileOutputNode;
  11. private AudioFileInputNode fileInputNode;
  12. private AudioDeviceOutputNode deviceOutputNode;
  13. private AudioDeviceInputNode deviceInputNode;
  14.  
  15. private async void Record()
  16. {
  17. if (audioGraph == null)
  18. {
  19. var settings = new AudioGraphSettings(AudioRenderCategory.Media);
  20. settings.EncodingProperties = recordingFormat.Audio;
  21. var res = await AudioGraph.CreateAsync(settings);
  22. if (res.Status != AudioGraphCreationStatus.Success)
  23. {
  24. Diagnostics += $"Audio Graph Creation Error: {res.Status}rn";
  25. return;
  26. }
  27.  
  28. audioGraph = res.Graph;
  29. audioGraph.UnrecoverableErrorOccurred += OnAudioGraphError;
  30. }
  31.  
  32. if (deviceInputNode == null)
  33. {
  34. var res = await audioGraph.CreateDeviceInputNodeAsync(MediaCategory.Speech,
  35. recordingFormat.Audio, SelectedInputDevice);
  36. // if you get AudioDeviceNodeCreationStatus.AccessDenied -
  37. //remember to add microphone capabilities
  38. if (res.Status != AudioDeviceNodeCreationStatus.Success)
  39. {
  40. Diagnostics += $"Device Input Node Error: {res.Status}rn";
  41. return;
  42. }
  43.  
  44. deviceInputNode = res.DeviceInputNode;
  45. }
  46.  
  47. var outputStorageFile = await SelectOutputFile();
  48. if (outputStorageFile != null)
  49. {
  50. var res = await audioGraph.CreateFileOutputNodeAsync(
  51. outputStorageFile, recordingFormat);
  52. if (res.Status != AudioFileNodeCreationStatus.Success)
  53. {
  54. Diagnostics += $"Output File Error: {res.Status}rn";
  55. return;
  56. }
  57.  
  58. fileOutputNode = res.FileOutputNode;
  59.  
  60. // construct the graph
  61. deviceInputNode.AddOutgoingConnection(fileOutputNode);
  62. }
  63.  
  64. audioGraph.Start();
  65. EnableCommands(true);
  66. Diagnostics += "Started recordingrn";
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement