录音机Windows手机7

时间:2013-01-05 15:02:45

标签: windows audio

我在Microsoft Visual Studio 2010,Windows手机上工作。 有人可以用录音机帮我。当我演奏时,我可以听到两次,但并非总是如此。之后,有人可以告诉我如何将其保存到隔离存储并从那里播放。 感谢。

private Microphone microphone = Microphone.Default;
    private byte[] buffer;
    private MemoryStream stream = new MemoryStream();
    private SoundEffect sound;
    int broj=0;
    void timer_Tick(object sender, EventArgs e)
    {
        if (microphone.State == MicrophoneState.Started)
        {
            microphone.Stop();
            timer.Stop();
        }


    }
    void microphone_BufferReady(object sender, EventArgs e)
    {
        microphone.GetData(buffer);
        stream.Write(buffer, 0, buffer.Length);
    }
    System.Windows.Threading.DispatcherTimer timer;

    public MainPage()
    {
        InitializeComponent();

        timer = new System.Windows.Threading.DispatcherTimer();
        timer.Interval = TimeSpan.FromMilliseconds(2000);
        timer.Tick += new EventHandler(timer_Tick);
        DispatcherTimer dt = new DispatcherTimer();
        dt.Interval = TimeSpan.FromMilliseconds(33);
        dt.Tick += new EventHandler(dt_Tick);
        dt.Start();
        microphone.BufferReady += new EventHandler<EventArgs>(microphone_BufferReady);
    }
    void dt_Tick(object sender, EventArgs e)
    {
        try { FrameworkDispatcher.Update(); }
        catch { }


    }


    private void button1_Click(object sender, RoutedEventArgs e)
    {
        ++broj;

        if ((broj + 1) % 2 == 0)
        {
            //FrameworkDispatcher.Update();
            microphone.BufferDuration = TimeSpan.FromMilliseconds(500);
            buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
            stream.SetLength(0);
            microphone.Start();
            timer.Start();

        }

        else
        {
            sound = new SoundEffect(stream.ToArray(), microphone.SampleRate, AudioChannels.Mono);
            sound.Play();

        }
    }

1 个答案:

答案 0 :(得分:0)

希望这个链接可以帮到你, 你需要理解基本逻辑的每一件事都在这里。 http://www.peteonsoftware.com/index.php/2010/06/23/windows-phone-7-microphone-and-isolated-storage/