Microphone in WPF application RRS feed

  • Question

  • I'm trying to record sound in a WPF app using XNA (sorry, new user registration for XNA forum seems to be down).

    This is my code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using System.Windows.Threading;
    namespace VowelRecog
        public partial class MainWindow : Window
            Microphone microphone;
            DispatcherTimer dispatcherTimer;
            byte[] buffer;
            public MainWindow()
                dispatcherTimer = new DispatcherTimer();
                dispatcherTimer.Interval = TimeSpan.FromTicks(333333);
                dispatcherTimer.Tick += OnTimerTick;
                buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
                microphone = Microphone.Default;
                microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
                microphone.BufferDuration = new System.TimeSpan(0, 0, 0, 1, 0);
            void microphone_BufferReady(object sender, EventArgs args)
    	        int n = microphone.GetSampleSizeInBytes(microphone.BufferDuration);
                int bytesReturned = microphone.GetData(buffer);
            void OnTimerTick(object sender, EventArgs args)
    However, microphone_BufferReady is never called. Any pointers? Thanks

    Tuesday, November 15, 2011 1:12 PM