1
我在Microsoft Visual Studio 2010,Windows手機上工作。 有人可以幫我用錄音機。當我彈奏它時,我可以聽到它兩次,但並不總是。之後,有人可以告訴我如何將其保存到獨立存儲並從那裏播放。 謝謝。錄音機Windows phone 7
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();
}
}