.net麦克风记录保存到windows phone 8中的文件中

本文关键字:文件 phone windows 麦克风 记录 保存 net | 更新日期: 2023-09-27 17:58:51

我需要知道如何在录制后动态地将声音流保存在文件中

这是我的代码,我需要保存一个外部文件wav或smth。

所以在这里有记录按钮播放按钮和播放对象

  private void recordButton_Click(object sender, EventArgs e)
    {
        // Get audio data in 1/2 second chunks
        microphone.BufferDuration = TimeSpan.FromMilliseconds(500);
        // Allocate memory to hold the audio data
        buffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
        // Set the stream back to zero in case there is already something in it
        stream.SetLength(0);
        // Start recording
        microphone.Start();
        SetButtonStates(false, false, true);
        UserHelp.Text = "recording";
        // StatusImage.Source = microphoneImage;
    }
      private void playButton_Click(object sender, EventArgs e)
    {
        if (stream.Length > 0)
        {
            // Update the UI to reflect that
            // sound is playing
            SetButtonStates(false, false, true);
            UserHelp.Text = "play";
            // Play the audio in a new thread so the UI can update.
            Thread soundThread = new Thread(new ThreadStart(playSound));
            soundThread.Start();
        }
    }
    private void playSound()
    {
        // Play audio using SoundEffectInstance so we can monitor it's State 
        // and update the UI in the dt_Tick handler when it is done playing.
        SoundEffect sound = new SoundEffect(stream.ToArray(), microphone.SampleRate, AudioChannels.Mono);
        soundInstance = sound.CreateInstance();
        soundIsPlaying = true;
        soundInstance.Play();
    }

.net麦克风记录保存到windows phone 8中的文件中

您需要正确构建.wav标头,然后编写音频流。检查此示例