I work in Microsoft Visual Studio 2010, Windows phone. Can someone help me with audio recorder. When I play it I can heard it twice but not always. After that can someone tell me how to save it to isolated storage and play it from there. Thanks.
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();
}
}
Hope this link may help you , Every thing you need to understand basic logic is here. http://www.peteonsoftware.com/index.php/2010/06/23/windows-phone-7-microphone-and-isolated-storage/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.