コード例 #1
0
ファイル: AudioCapture.cs プロジェクト: maria-chang/psi
 /// <summary>
 /// Stops capturing audio data.
 /// </summary>
 public void StopCapture()
 {
     if (this.wasapiCapture != null)
     {
         this.wasapiCapture.Dispose();
         this.wasapiCapture = null;
     }
 }
コード例 #2
0
ファイル: AudioCapture.cs プロジェクト: vdedyukhin/psi
        /// <summary>
        /// Initializes a new instance of the <see cref="AudioCapture"/> class.
        /// </summary>
        /// <param name="pipeline">The pipeline to add the component to.</param>
        /// <param name="configuration">The component configuration.</param>
        public AudioCapture(Pipeline pipeline, AudioCaptureConfiguration configuration)
        {
            this.pipeline        = pipeline;
            this.configuration   = configuration;
            this.audioBuffers    = pipeline.CreateEmitter <AudioBuffer>(this, "AudioBuffers");
            this.AudioLevelInput = pipeline.CreateReceiver <double>(this, this.SetAudioLevel, nameof(this.AudioLevelInput), true);
            this.AudioLevel      = pipeline.CreateEmitter <double>(this, nameof(this.AudioLevel));

            this.wasapiCapture = new WasapiCapture();
            this.wasapiCapture.Initialize(this.Configuration.DeviceName);

            if (this.Configuration.AudioLevel >= 0)
            {
                this.wasapiCapture.AudioLevel = this.Configuration.AudioLevel;
            }
        }
コード例 #3
0
ファイル: AudioCapture.cs プロジェクト: maria-chang/psi
        /// <summary>
        /// Starts capturing audio data.
        /// </summary>
        /// <param name="targetLatencyInMs">
        /// The target maximum number of milliseconds of acceptable lag between
        /// live sound being produced and capture operation.
        /// </param>
        /// <param name="gain">
        /// The gain to be applied to the captured audio.
        /// </param>
        /// <param name="outFormat">
        /// The desired output format of the captured audio.
        /// </param>
        /// <param name="speech">
        /// If true, optimizes the audio capture pipeline for speech recognition.
        /// </param>
        public void StartCapture(int targetLatencyInMs, float gain, WaveFormat outFormat, bool speech)
        {
            if (this.wasapiCapture != null)
            {
                this.StopCapture();
            }

            this.wasapiCapture = new WasapiCapture(this.audioDevice);

            // Create a callback delegate and marshal it to a function pointer. Keep a
            // reference to the delegate as a class field to prevent it from being GC'd.
            this.callbackDelegate = new AudioDataAvailableCallback(this.AudioDataAvailableCallback);

            // initialize the capture with the desired parameters
            this.wasapiCapture.Initialize(targetLatencyInMs, gain, outFormat, this.callbackDelegate, speech);

            // tell WASAPI to start capturing
            this.wasapiCapture.Start();
        }
コード例 #4
0
ファイル: AudioCapture.cs プロジェクト: vdedyukhin/psi
 /// <summary>
 /// Static method to get the available audio capture devices.
 /// </summary>
 /// <returns>
 /// An array of available capture device names.
 /// </returns>
 public static string[] GetAvailableDevices()
 {
     return(WasapiCapture.GetAvailableCaptureDevices());
 }