示例#1
0
        public AudioRecorderViewModel(Microphone microphone, byte[] buffer, OpusRuntimeComponent opusComponent, Action <double> decibelValueChangedCallback, Action recordingStoppedCallback, Action recordingStoppedWithTimeoutCallback)
        {
            AudioRecorderViewModel recorderViewModel = this;

            this._microphone    = microphone;
            this._buffer        = buffer;
            this._opusComponent = opusComponent;
            this._decibelValueChangedCallback = decibelValueChangedCallback;
            this._recordingStoppedCallback    = recordingStoppedCallback;
            this._asyncDispatcher             = new XnaAsyncDispatcher((Action)(() =>
            {
                recorderViewModel._recordFinishTime = DateTime.Now;
                TimeSpan timeSpan = recorderViewModel._recordFinishTime - recorderViewModel._recordStartTime;
                recorderViewModel.RecordDurationStr = timeSpan.ToString(timeSpan.Hours > 0 ? "h\\:m\\:ss" : "m\\:ss");
                recorderViewModel.RecordDuration = (int)timeSpan.TotalMilliseconds;
                if (recorderViewModel.RecordDuration < AudioRecorderViewModel.GetMaxDuration())
                {
                    return;
                }
                recorderViewModel.StopRecording();
                Action action = recordingStoppedWithTimeoutCallback;
                if (action == null)
                {
                    return;
                }
                action();
            }));
        }
示例#2
0
 public AudioRecorderUC()
 {
     //base.\u002Ector();
     this.InitializeComponent();
     if (DesignerProperties.IsInDesignTool)
     {
         return;
     }
     if (!AudioRecorderHelper.CanRecord)
     {
         return;
     }
     try
     {
         this._microphone = Microphone.Default;
         this._microphone.BufferDuration = this._bufferDuration;
         this._buffer        = new byte[this._microphone.GetSampleSizeInBytes(this._bufferDuration)];
         this._opusComponent = new OpusRuntimeComponent();
     }
     catch
     {
     }
 }
示例#3
0
        public static MemoryStream GetAsWavStream(string filePath, int sampleRate, int audioChannels, int bitsPerSample)
        {
            OpusRuntimeComponent runtimeComponent = new OpusRuntimeComponent();

            if (runtimeComponent.InitPlayer(filePath) != 1)
            {
                return(null);
            }
            byte[]       buffer = new byte[16384];
            int[]        args   = new int[3];
            MemoryStream data   = new MemoryStream();
            int          num1;

            do
            {
                runtimeComponent.FillBuffer(buffer, buffer.Length, args);
                int count = args[0];
                int num2  = args[1];
                num1 = args[2] == 1 ? 1 : 0;
                data.Write(buffer, 0, count);
            }while (num1 == 0);
            return(data.GetWavAsMemoryStream(sampleRate, audioChannels, bitsPerSample));
        }