我在 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();
}
}